Skip to main content
Participant
May 4, 2020
Question

Variable undefined errors after upgrading to ColdFusion 2016 Update 12 and onwards

  • May 4, 2020
  • 2 replies
  • 1524 views

Hello ,

 

We have been facing certain issues in our application post upgrade from ColdFusion 2016 Update 11 to Update 12 onwards till Update 15. We are now at ColdFusion 2016 Update 15 and still facing the same issue.

 

The application is not able to identify the varibables inside the nested structure in the  <CFIF> <CFELSE> tag. The problem only comes if we have a <CFELSE> tag. If we remove the <CFELSE> tag, the issue goes away. This is hampering all of our application.

If you see the code below- 

<CFOUTPUT>
<cfset strAdminName = 'testName'/>
<cfif strAdminName NEQ ''>
#objML.writePrompt('msgContactAdminWithContact', '?AdminName?', stcMLRej, {AdminName=strAdminName})#
<cfelse>
#objML.writePrompt('msgContactAdminNoContact', 'If you have a question regarding your username and password, contact your system administrator.', stcMLRej)#
</cfif>
</CFOUTPUT>


*writePrompt is a function.

 

Error:- Variable STRADMINNAME is undefined.
Can you please help here to resolve this to make our application running .

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    May 5, 2020

    I have just discovered that the error disappears when you place the variable definitions outside the cfoutput tags. Which is the recommended way to code anyway. But this is not to absolve ColdFusion.

     

    Examples:

    <!--- Placed outside cfoutput tags --->
    <cfset strAdminName = 'testName'/>
    
    <CFOUTPUT>
    <cfif strAdminName NEQ ''>
    #objML.writePrompt('msgContactAdminWithContact', '?AdminName?', stcMLRej, {AdminName=strAdminName})#
    <cfelse>
    #objML.writePrompt('msgContactAdminNoContact', 'If you have a question regarding your username and password, contact your system administrator.', stcMLRej)#
    </cfif>
    </CFOUTPUT>
    
    <!--- Second example ---> 
    
    <cfset strAdminName = 'testName'/>
    
    <cfif strAdminName NEQ ''>
    <CFOUTPUT>#objML.writePrompt('msgContactAdminWithContact', '?AdminName?', stcMLRej, {AdminName=strAdminName})#</CFOUTPUT>
    <cfelse>
    <CFOUTPUT>#objML.writePrompt('msgContactAdminNoContact', 'If you have a question regarding your username and password, contact your system administrator.', stcMLRej)#</CFOUTPUT>
    </cfif>
    
    
    <!--- Third example is even better; it is in fact best-practice ---> 
    
    <cfset strAdminName = 'testName'/>
    <cfset myStruct = {AdminName=strAdminName}>
    <cfif strAdminName NEQ ''>
    <CFOUTPUT>#objML.writePrompt('msgContactAdminWithContact', '?AdminName?', stcMLRej, myStruct)#</CFOUTPUT>
    <cfelse>
    <CFOUTPUT>#objML.writePrompt('msgContactAdminNoContact', 'If you have a question regarding your username and password, contact your system administrator.', stcMLRej)#</CFOUTPUT>
    </cfif>
    
    Participant
    May 5, 2020

    The thing is that there are code related workarounds available, but our application has a lot of pages where this situation might arise.
    We want to just upgrade the CF version without having to make a whole lot of code changes.

    BKBK
    Community Expert
    Community Expert
    May 5, 2020

    This behaviour is likely to be a bug. Moreover, I do understand your need to upgrade ColdFusion without having to make a lot of code changes. 

     

    But some changes, like the one I pointed out, are definitely worthwhile. If you do it right first time, then there is every chance you won't have to worry about this upgrade or that update. That is the main reason for adhering to best-practice. It's an investment today, with a huge payback in the long run.

    WolfShade
    Legend
    May 4, 2020

    As I understand it, everything is evaluated in an if/else statement; all of it, even the stuff that doesn't apply.  This should be fixable by using a switch/case instead of if/else.  The server iterates through the cases until it finds the one that matches, and then processes the code, and only that code.

     

    But I'm a bit perplexed.  In your cfelse statement, there is no STRADMINNAME variable being called.  So removing the cfelse shouldn't "fix" this.

     

    Have you filed a bug with TRACKER?

     

    HTH,

     

    ^ _ ^

    Participant
    May 5, 2020

    I see a similar issue already created in tracker which seems unresolved.

    https://tracker.adobe.com/#/view/CF-4207294