Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 16, 2008 Oct 16, 2008
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>
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Oct 17, 2008 Oct 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(f...
Translate
Valorous Hero ,
Oct 16, 2008 Oct 16, 2008
brad92008 wrote:
> <cfdump var=#Request.vSurveyLmicodes#>
> #request.vRollCodes[request.vRollCode]#

Those are two different structures. Is that a typo?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2008 Oct 16, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2008 Oct 16, 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2008 Oct 16, 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....'
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2008 Oct 16, 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 17, 2008 Oct 17, 2008
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources