Skip to main content
Known Participant
April 8, 2008
Answered

IsDefined for Structures

  • April 8, 2008
  • 2 replies
  • 388 views
I have a report where I'm using cftry as a bandaid until I get a better answer. How can I determine if the following exists? Using it as is returns an error "must be a syntactically valid variable name".

This topic has been closed for replies.
Correct answer -__cfSearching__-
If Row is always a structure, try using structKeyExists

<cfif StructKeyExists(Row
, "MTD_TypeTotal")>

If not, try adding IsStruct

<cfif IsStruct(Row ) AND StructKeyExists(Row, "MTD_TypeTotal")>

2 replies

-__cfSearching__-Correct answer
Inspiring
April 8, 2008
If Row is always a structure, try using structKeyExists

<cfif StructKeyExists(Row
, "MTD_TypeTotal")>

If not, try adding IsStruct

<cfif IsStruct(Row ) AND StructKeyExists(Row, "MTD_TypeTotal")>
Inspiring
April 8, 2008
> cfif IsDefined("Row .MTD_TypeTotal")

Which version of CF are you running?

1) you cannot do it in one hit.
2) you need to first establish whether Row
exists.
3) contingent on the answer to (2), you need to check if Row has a key
"MTD_TypeTotal".

(2) is easy in CF8, as there's an array function to test for such things.
http://livedocs.adobe.com/coldfusion/8/functions-pt0_03.html

It's not so easy in CF7 or earlier, but if you search around these forums
or Google, you'll come up with some options.

(3) is covered by a struct function.
http://livedocs.adobe.com/coldfusion/8/functions-pt0_19.html

In dealing with issues like this, it'ds always handy to check the docs
before asking the question: you'll learn more if you try to DIY.

--
Adam
NewPrismAuthor
Known Participant
April 8, 2008
Adam, thanks. I'm devloping in 7 and posting to different servers, the lowest has 7.

The StructKeyExists was the short answer, but I've followed your livedoc links which were both good resources.

Tim