Skip to main content
Participating Frequently
April 27, 2023
Question

Case sensitive structs error

  • April 27, 2023
  • 2 replies
  • 1101 views

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.

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
April 28, 2023
quote

This is only happening in structs that are made from cfqueries. All other structs appear to be case-insensitive. 


By @Amanjot5EDD

 

Could you also share the code that "makes" structs from cfqueries.

Participating Frequently
April 28, 2023

The following query returns an array of structs.

 

BKBK
Community Expert
Community Expert
April 29, 2023

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.

BKBK
Community Expert
Community Expert
April 28, 2023

Could you please share with the forum the full exception message. Also share the line of code at which the error occurs.

Participating Frequently
April 28, 2023

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>