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

isDefined not working since migration to CF11

Community Beginner ,
Sep 26, 2017 Sep 26, 2017

Copy link to clipboard

Copied

Hello!

We have a system running on Cold Fusion. The server was running on CF7 and we upgraded it to CF11 and now the isDefined are not working anymore.

To be honest I do very few Cold Fusion coding, it's an old system that was not maintained that I just got and I have to manage. I am learning everything.

I've read that isDefined is not the best and would be better to use structKeyExists instead. The problem is there is more than 1900 files and 3000 isDefined to change.

Example :

This line marks an error :

<cfif not isdefined("caller.#attributes.prefix_mandatory##fldname#") or  (isdefined("caller.#attributes.prefix_mandatory##fldname#") and trim(evaluate("caller.#attributes.prefix_mandatory##fldname#")) is "")>

Which I corrected and works fine :

<cfif not structKeyExists(caller, '#attributes.prefix_mandatory##fldname#') or (structKeyExists(caller,'#attributes.prefix_mandatory##fldname#"') and trim(evaluate("caller.#attributes.prefix_mandatory##fldname#")) is "")>

Error message :

"Error","ajp-bio-8014-exec-1","09/26/17","09:59:25","database_name","Complex object types cannot be converted to simple values.The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. <p> The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag. The specific sequence of files included or processed is: [FILE_PATH], line: 160 "

I have the same problem on my local Cold Fusion Builder than on the Web Server (our DEV environment), both on CF11.

Is it normal that it use to work great but it's not working anymore? Is there another workaround or another thing I missed (ex. Admin setting, other configuration, etc) ? I'd like to find a solution that would not necessitate to change the code.

Views

531

Translate

Translate

Report

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

Community Beginner , Oct 04, 2017 Oct 04, 2017

Finally the problem was not there at all, but in the data sent to this process. We had somewhere in the code 2 different variables with the same name, but they were not interacting with each other. One was containing a value and the other one is an array, and even if they don't touch at the same modules, they interfered one with each other. While moving to CF11 it became a problem and now we just renamed a variable without modifying all the code up here.

Thanks for your help,

I hope this might s

...

Votes

Translate

Translate
Community Expert ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

IsDefined is working. But it works differently from structKeyExists.

When you work with isDefined you have to be careful about certain things. The function expects, as argument, the full, scoped name of the test variable. For example, variables.x, form.y or caller.z. So the function does not expect you to use ## to evaluate dynamic variables within the argument. When you perform such evaluations, you risk error.

In fact, I suspect that the difference in the behaviour of isDefined between ColdFusion versions is due to subtle differences in order of processing. Isdefined("caller.#attributes.prefix_mandatory##fldname#")assumes that the order of evaluation is something like

#attributes.prefix_mandatory#

#fldname#

concatenation #attributes.prefix_mandatory##fldname#

result "caller.#attributes.prefix_mandatory##fldname#"

Different versions of ColdFusion may evaluate this in a different order. Perhaps the same version of ColdFusion may do the evaluation in a different order, depending on the circumstances.

As you have discovered, structKeyExists is more suitable when the variable name has to be evaluated dynamically. I think it is the best workaround. Should any isDefined call break, just replace it, as you have done, with structKeyExists. For the remaining hundreds of cases, I would say, if it ain't broke...

Votes

Translate

Translate

Report

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
Community Beginner ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

Thanks for your answer BKBK.

For now it seems the only places where the problem occurs is in CustomTags, and not on the "normal" website. I hope it's the case, it is very hard to test everything because that thing is messy and huge (over 1900 pages !?!!!).

What you are teached me is I didn't missed a configuration somewhere but I hope I will not have to change a lot of code and that it's going to work fine from now on, after making few corrections in Custom Tags.

Maybe the Custom Tags are evaluated in a different order since the migration to CF11.

- Séb

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 04, 2017 Oct 04, 2017

Copy link to clipboard

Copied

Finally the problem was not there at all, but in the data sent to this process. We had somewhere in the code 2 different variables with the same name, but they were not interacting with each other. One was containing a value and the other one is an array, and even if they don't touch at the same modules, they interfered one with each other. While moving to CF11 it became a problem and now we just renamed a variable without modifying all the code up here.

Thanks for your help,

I hope this might serve another someone in the future,

- Séb

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 04, 2017 Oct 04, 2017

Copy link to clipboard

Copied

LATEST

Hi Séb, thanks for sharing that with us!

Votes

Translate

Translate

Report

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
Documentation