Search code examples
coldfusioncoldfusion-9cfml

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


I am getting this error in one of my pages: Element 9 is undefined in a CFML structure referenced as part of an expression. I even tried to dump that specific structure and result is same.

<cfdump var="#(request.session.cust.dra_info[versionid].bm[gradecd]#">

Error

The [VerionID] is the reason i am getting this error. Versionid might be coming as 9 which doesnt exists. This versionid and gradecd is coming from a query. Here is the dump of that query: Query

The dump of the structure gives me below result:

<cfdump var="#request.session.cust.dra_info#">

enter image description here

Any help/suggestion how should i handle this error?


Solution

  • This error means "You are passing a value (in your case 9) which is not present in the structure". This value might refer to versionId or gradecd.
    You need pass only those values which are available in the structure. I can not say how to do that without looking at code.

    EDIT
    You can do like this

    <cfif structKeyExists(request.session.cust.dra_info,"#versionId#")>
        <cfdump var="#(request.session.cust.dra_info[versionid].bm[gradecd]#"><cfabort>
    <cfelse>    
        <cfdump var="not ok- error handling code"><cfabort>
    </cfif>