Skip to main content
Participant
October 16, 2008
Answered

Element CF022 is undefined in a CFML structure referenced as part of an expression

  • October 16, 2008
  • 6 replies
  • 3543 views
I have a structrue called vRollCodes. It is defined and has a single key,value pair stored in it... i.e.,

<cfdump var=#Request.vSurveyLmicodes#>
CF022 | NY

but when I pass in the key 'CF022'

Request.vRollCodes[request.vRollCode] - where req.vRollCode = 'CF022'

it doesn't return 'NY' instead i get...

Element CF022 is undefined in a CFML structure referenced as part of an expression.

The error occurred in D:\Inetpub\wwwroot\USW\Common\PROF\Industry\Compare\cmpMainDsp.cfm: line 278

278 : <font class="subtitle2">in #request.vRollCodes[request.vRollCode]#</b></font>
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer brad92008
    Thanks - that helped me find the issue... there was padding in the structure[key] - value... I had looked for that earlier using Enterprise Manager but it automatically trimmed the values for me so even though the value was really - 'CF022 ' sql was returning 'CF022' or len = 5 not 10..... I ended up writing a test app to interogate the key length in multiple DBs adn tables.. and check the actual lengths. When I found the offending table/fields I just did a quick update table set field = rtrim(field).. and it worked fine.

    6 replies

    brad92008AuthorCorrect answer
    Participant
    October 17, 2008
    Thanks - that helped me find the issue... there was padding in the structure[key] - value... I had looked for that earlier using Enterprise Manager but it automatically trimmed the values for me so even though the value was really - 'CF022 ' sql was returning 'CF022' or len = 5 not 10..... I ended up writing a test app to interogate the key length in multiple DBs adn tables.. and check the actual lengths. When I found the offending table/fields I just did a quick update table set field = rtrim(field).. and it worked fine.
    Inspiring
    October 17, 2008
    Try comparing the ascii values. Are there any differences?

    <cfset string1 = structKeyList(request.vRollCodes)>
    <cfset string2 = request.vRollCode>

    <cfoutput>
    string1:<br>
    <cfloop from="1" to="#len(string1)#" index="c">
    <cfset char = mid(string1, c, 1)>
    position[#c#]: #char# #asc(char)#<br>
    </cfloop>

    string2:<br>
    <cfloop from="1" to="#len(string2)#" index="c">
    <cfset char = mid(string2, c, 1)>
    position[#c#]: #char# #asc(char)#<br>
    </cfloop>
    </cfoutput>
    brad92008Author
    Participant
    October 17, 2008
    If I dump just the structure: vRollCodes - I get:

    CF022 | NY

    If I try to dump the structure with the key index:
    vRollCodes[vRollCode] - I get the error.. i.e., vRollCode = 'CF022'..

    'Element CF022 is undefined....'
    Inspiring
    October 17, 2008
    I would say first verify the simple things. Dump the structureKeyList and the key (before the error). Just to be absolutely certain the values are what you think they are.

    <cfdump var="#structKeyList(request.vRollCodes)#">
    <cfdump var="#request.vRollCode#">

    If they appear the match visually, examine the ascii values of each character. Leading or trailing whitespace might account for the difference. Notice the key is not found due to the trailing whitespace.

    <cfset request.vRollCodes = structNew()>
    <!--- deliberately add trailing whitespace --->
    <cfset request.vRollCodes["CF022 "]= "NY">
    <cfset request.vRollCode = "CF022">
    <cfif structKeyExists(request.vRollCodes, request.vRollCode)>
    Key found
    <cfelse>
    NOT FOUND
    </cfif>
    Inspiring
    October 16, 2008
    brad92008 wrote:
    > <cfdump var=#Request.vSurveyLmicodes#>
    > #request.vRollCodes[request.vRollCode]#

    Those are two different structures. Is that a typo?
    brad92008Author
    Participant
    October 17, 2008
    Yeah thats a typo - I was trying to change the names to protect the innocent.. The structure is populated however, when I try to access the value when passing in the key.. ie.., #Request.vStrucure[Request.Key].... I get the error.

    Thanks