Skip to main content
2Charlie
Inspiring
January 31, 2018
Question

Why is my IF statement not working?

  • January 31, 2018
  • 2 replies
  • 2718 views

Here's my current IF statement that is not working.

<cfif (not structKeyExists(cfData, 'data.remove_pdf')) OR (structKeyExists(cfData, 'data.remove_pdf') AND #cfData.data.remove_pdf# neq "true")>

<a href="https://mysite.com/help/pdfexport/id/#cfData.data.id#">

<img src="/images/pdficon_small.png" alt="PDF of this article"/>

</a>

</cfif>

I want to say if remove_pdf field is undefined or if it’s defined but the value is not equal to true then show the pdf icon. When I dump the #cfData#, it shows remove_pdf value as undefined or true.

    This topic has been closed for replies.

    2 replies

    Inspiring
    January 31, 2018

    I doubt that you want to use data.remove_pdf as a string literal, but that is what is happening above.  What structKeyExists(cfData, 'data.remove_pdf') means is that the string data.remove_pdf is the literal name of the key it is looking for (cfData['data.remove_pdf']).  Not exactly sure what you are trying to do, but are you maybe looking to see if the remove_pdf key exists in data like structKeyExists(data, 'remove_pdf')?

    -Nic

    2Charlie
    2CharlieAuthor
    Inspiring
    January 31, 2018

    I want to test if the field remove_pdf is defined. If it is, is the value not equal true?

    WolfShade
    Legend
    January 31, 2018

    Remove the quotes and the hashtags.

    1. <cfif (not structKeyExists(cfData, data.remove_pdf)) OR (structKeyExists(cfData, data.remove_pdf) AND cfData.data.remove_pdf neq "true")> 
    2. <a href="https://mysite.com/help/pdfexport/id/#cfData.data.id#"> 
    3. <img src="/images/pdficon_small.png" alt="PDF of this article"/> 
    4. </a> 
    5. </cfif>

    V/r,

    ^ _ ^

    2Charlie
    2CharlieAuthor
    Inspiring
    January 31, 2018

    Are you referring to removing the quotes and hash tags on these lines?

    1. <a href="https://mysite.com/help/pdfexport/id/#cfData.data.id#">   
    2. <img src="/images/pdficon_small.png" alt="PDF of this article"/>   
    3. </a>  
    WolfShade
    Legend
    January 31, 2018

    No.. the quotes and hashtags on line 1.

    V/r,

    ^ _ ^