Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

IsDefined for Structures

New Here ,
Apr 08, 2008 Apr 08, 2008
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".

TOPICS
Advanced techniques
342
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Apr 08, 2008 Apr 08, 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")>
Translate
LEGEND ,
Apr 08, 2008 Apr 08, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2008 Apr 08, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2008 Apr 08, 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")>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources