Skip to main content
September 28, 2010
Answered

checking exsistance of query inside a struct

  • September 28, 2010
  • 1 reply
  • 427 views

in CF 7

I want to do this...

<cfif isdefined('variables.getReport["STATUS"][1]')>

<!--- do stuff --->

</cfif>

But it seems CF does not like this convention. Even though its happy enough to use the same convention NOT within a isdefined statement.

Any ideas how else I could test for the existance of 'variables.getReport["STATUS"][1] ?

    This topic has been closed for replies.
    Correct answer ilssac

    Is defined takes a string and checks to see if there are any variables named with the same string.

    "variables.getReport" is the variable name.

    ["STATUS"][1] are a structure key and array index of that variable, but has nothing to do with the variable name.

    <cfif isDefined("variables.getReport") AND 
          structKeyExists(variables.getReport,"STATUS") AND
          arrayIsDefined(variables.getReport["STATUS"],1>

    Is how one might check all three layers of that variable.

    Message was edited by: ilssac     Sorry, arrayIsDefined() was added in CF 8, rereading I see you are on CF7.  Until you update, you would have to use something like "arrayLen(variables.getReport["STATUS"]) GTE 1" for the third test.

    1 reply

    ilssac
    ilssacCorrect answer
    Inspiring
    September 28, 2010

    Is defined takes a string and checks to see if there are any variables named with the same string.

    "variables.getReport" is the variable name.

    ["STATUS"][1] are a structure key and array index of that variable, but has nothing to do with the variable name.

    <cfif isDefined("variables.getReport") AND 
          structKeyExists(variables.getReport,"STATUS") AND
          arrayIsDefined(variables.getReport["STATUS"],1>

    Is how one might check all three layers of that variable.

    Message was edited by: ilssac     Sorry, arrayIsDefined() was added in CF 8, rereading I see you are on CF7.  Until you update, you would have to use something like "arrayLen(variables.getReport["STATUS"]) GTE 1" for the third test.