Complex object types cannot be converted to simple values

Tag: coldfusion , coldfusion-10 Author: ms9ms2 Date: 2014-01-21

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.

Best Answer

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

EDIT: non-cfscript as requested

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

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

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


Can you translate this without using <cfscript> please?
Dude, it is an if statement. I think thats pretty straightforward.
All set, but seriously, asking for help is one thing, asking for others to write your code for you is not the point of this site. Next time try reading the docs for the function you're using first. It clearly states it returns an array. Hence the "complex object cannot be converted to simple value" error. An array can never be compared to zero as you showed in your question.
okay thank you very much!
on a side note, i'm confused why it doesn't need the number signs. because i'm asking it to evaluate ApplicationArea and replace it with the correct value. How does it know that I'm not asking it to look in a struct key named 'ApplicationArea' ?