Question

Using: CF10

I'm storing the key value of a struct in a variable as such:

<cfset ApplicationArea = '1'>

I want to find if this value exists in a struct like such:

StructKeyExists(SESSION.Auth.AccessA, #ApplicationArea#)

This all works. However, within the struct of SESSION.Auth.AccessA["1"] are further keys. I now need to find if a certain key exists in this struct. This is what I came up with but does not work:

StructFindValue(SESSION.Auth.AccessA[#ApplicationArea#], '3') GT 0

I get the error of "Complex object types cannot be converted to simple values."

I want to know if the value of '3' exists in the struct of SESSION.Auth.AccessA["1"] (which it does when I dump the SESSION variable). I might have got my explanation confused slightly but I think its correct.

Was it helpful?

Solution

<cfscript>
if (ArrayLen(StructFindValue(SESSION.Auth.AccessA[ApplicationArea], '3', 'ALL'))) {
    // it exists
} else {
    // it does not
}
</cfscript>

EDIT: non-cfscript as requested

<cfif ArrayLen(StructFindValue(SESSION.Auth.AccessA[ApplicationArea], '3', 'ALL'))>
    <!--- it exists --->
<cfelse>
    <!--- it does not --->
</cfif>

StructFindValue returns an array of structures containing information about the keys that match the value.

https://wikidocs.adobe.com/wiki/display/coldfusionen/StructFindValue

You don't need any of the # chars in your question (I know you asked about when and when not to use them recently)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top