Skip to main content
August 30, 2011
Answered

CFIF / CFELSEIF / CFIF

  • August 30, 2011
  • 2 replies
  • 1814 views

I am new to coldfusion and need to create an automated email that will send emails depending on what the company name is.  I can get the cfif / cfelse statement to work properly.  When I try to get the cfif / cfelseif / cfelse the cfelseif appears to not be evaluated.  Here is a segment of code.

<cfquery  name="get_ticket_info" datasource="#application.datasource#"username="#application.datasource_username#" password="#application.datasource_password#">
SELECT * FROM
    tbl_Tickets
    WHERE ID_NO = <cfqueryparam cfsqltype="cf_sql_smallint" value="#id#">;
</cfquery>

<cfif get_ticket_info.customer_name is "Company A"><cfset tolist="john.doe@companyA.com">
<cfelseif get_ticket_info.customer_name is "Company B"><cfset tolist="jane.doe@companyB.com">
<cfelse><cfset tolist="frank.doe@companyY.com">
</cfif>

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    I troubleshoot if/else logic by looking at the data.  For your example, it would be something like this:

    <cfdump var="#get_ticket_info#" metainfo = "no">

    <cfif get_ticket_info.customer_name is "Company A"><cfset tolist="john.doe@companyA.com">

    <br> is company a
    <cfelseif get_ticket_info.customer_name is "Company B"><cfset tolist="jane.doe@companyB.com">

    <br> is company b
    <cfelse>

    <cfset tolist="frank.doe@companyY.com">

    <br> is neither company a nor b.

    <br><cfdump var = "_#get_ticket_info.customer_name#_">
    </cfif>

    <cfabort>

    2 replies

    Legend
    August 30, 2011

    Nothing jumps out at me as incorrect. My guess is no customer_name is "Company B". Maybe the name is space padded? Try using <cfdump var="#get_ticket_info#" /> or use cflog to log various values and compare the data yourself.

    August 30, 2011

    Steve,

    That is exactly what it was.  Thank you for your suggestion.

    Dan_BracukCorrect answer
    Inspiring
    August 30, 2011

    I troubleshoot if/else logic by looking at the data.  For your example, it would be something like this:

    <cfdump var="#get_ticket_info#" metainfo = "no">

    <cfif get_ticket_info.customer_name is "Company A"><cfset tolist="john.doe@companyA.com">

    <br> is company a
    <cfelseif get_ticket_info.customer_name is "Company B"><cfset tolist="jane.doe@companyB.com">

    <br> is company b
    <cfelse>

    <cfset tolist="frank.doe@companyY.com">

    <br> is neither company a nor b.

    <br><cfdump var = "_#get_ticket_info.customer_name#_">
    </cfif>

    <cfabort>

    August 30, 2011

    Dan,

    By taking your suggestion I discovered a space at the end of the company name.  Thank you for your assistance.