We just recently upgraded from CF2018 to CF2021. Since ColdFusion converts all struct keys into uppercase, we're now getting UndefinedElementException when we try to refer to struct keys in lowercase (it worked fine in cf2018). This is only happening in structs that are made from cfqueries. All other structs appear to be case-insensitive. We tried adding this.serialization.preserveCaseForStructKey in application settings, but it didn't help.
Could you please share with the forum the full exception message. Also share the line of code at which the error occurs.
We then loop over the returned array and try to access MeetingID at which point an error is thrown.
This is the line where it happens:
<cfloop array="#upcomingprograms#" index="j"> <li><a href="#Application.globals.rootWEB#prog/sessions.cfm?course_id=#j.MeetingID#"> (#DateFormat(j.StartDate, 'dd-mmm')#)</li>
The following query returns an array of structs.
Thanks for sharing the error-message and code. What happens when you do the following test?
Test: Replace your loop code with the following equivalent version.
<cfif isArray(upcomingprograms)> <cfloop array="#upcomingprograms#" index="j"> <cfif isStruct(j)> <!--- If MeetingID key exists, set it to a value, using associative array syntax ---> <cfif structKeyExists(j, "MeetingID")> <cfset currentMeetingID=j["MeetingID"]> <li><a href="#Application.globals.rootWEB#prog/sessions.cfm?course_id=#currentMeetingID#"> </cfif> ... ... <cfelse> <!--- Error-handling: j is not a structure! ---> </cfif> </cfloop> <cfelse> <!--- Error-handling: upcomingprograms is not an array! ---> </cfif>
Do the test with this.serialization.preserveCaseForStructKey=false, then with this.serialization.preserveCaseForStructKey=true.
That is strange. The structs J should not be case-sensitive by default.
In the meantime, here's a suggestion: try to force ColdFusion to use a case-insensitive struct, jNew, in place of the case-sensitive j. The code follows:
<cfloop array="#upcomingprograms#" index="j"> <!--- Initialize case-insensitive struct ---> <cfset jNew=StructNew()> <!--- Make a deep copy of j and store it as jNew ---> <cfset jNew=duplicate(j); <!--- In the rest of the loop code, replace every occurrence of j with jNew ---> ... ... ... </cfloop>
Also, IsStruct(j) returns YES, and if I try j.getMetaData(), the following exception is thrown.
Great debugging there, @Amanjot5EDD .
It provides yet another confirmation that there is a bug. In the original error message, "Element MeetingID is undefined in J", ColdFusion sees j's type as "coldfusion.runtime.DotResolver.resolveSplitNameInMap".
Strictly speaking, that is not a struct. However, it may perhaps be cast to a case-sensitive struct. Which would explain everything you've observed so far.
When you report a bug, it will help to add a link to this forum page.