Solved

Changing CFMAIL parameter with CFIF statement in Coldfusion

Posted on 2014-12-28
9
131 Views
Last Modified: 2014-12-29
Hi,

  I have CFM page where I send online order confirmation email to recipients using CFMAIL   .When the salesperson completes the order, then the email confirmation goes to the person who ordered it and the person who is designated to process the order. But if the salesperson ID is 13 or 12, then it goes to one more person  using BCC (ie.  BCC="user@ABC.com").  In CFMAIL, there is a table which shows the order informaiton.
But the contents of the table is the same regardless of saleperon's ID. The only difference is BCC in CFMAIL.
I like to be able to keep just one <TABLE> ... </TABLE> using CFIF ... CFELSE. Unfortunately I have to maintain two <TABLE> ... </TABLE>. If there is an update in <TABLE> ... </TABLE>, then I have to make the same change in two separate TABLEs. How can I combine these two TABLEs into one?

---------------------------------------------------------------------------------------------------
<CFIF "#session.LoginID#" IS '13' or "#session.LoginID#" IS '12'>
    <CFMAIL                  
      FROM="order@ABC.com"
      TO="#session.Email#"
        CC="#Form.Processor#"
        BCC="user@ABC.com"
      SUBJECT="*#ORDERTYPE#* New Bag Order Notification for Order No:#OrderNumber.LastRecord#" TYPE="HTML">

        <TABLE width=800 border=0 cellpadding=2 cellspacing=1  valign="top" align="CENTER">
      <TR bgcolor="304A00">
            <TD colspan=4 bgcolor="304A00" align=center><font FACE="verdana,arial,helvetica" size=3 color=B5D083>
            <B>NOTIFICATION OF NEW BAG ORDER</B><BR>
        Order No:<B>#OrderNumber.LastRecord#</B>&nbsp;&nbsp;&nbsp;&nbsp;ORDER TYPE: &nbsp;<B>#ORDERTYPE#</B></font>
            </TD>
      </TR>
        <!--- Ship To --->
      <TR>
          <TD bgcolor="B5D083"><font FACE="verdana,arial,helvetica" size=1>
                  <b>Ship To:</b></font></TD>
          <td bgcolor="white"><font  FACE="verdana,arial,helvetica" size=1>
                  #Shipto1#
            </TD>
          <TD bgcolor="B5D083"><font FACE="verdana,arial,helvetica" size=1>
                  <b>Order Date:</b></font></TD>
          <td bgcolor="white"><font  FACE="verdana,arial,helvetica" size=1>
                  #DateFormat(now(), "mm/dd/yy")#
            </TD>
      </TR>

        ...... more code ......
        </TABLE>

    </CFMAIL>

<CFELSE>
    <CFMAIL      
            FROM="order@ABC.com"
            TO="#session.Email#"
                CC="#Form.Processor#"
            SUBJECT="*#ORDERTYPE#* New Bag Order Notification for Order No:#OrderNumber.LastRecord#"
            TYPE="HTML">

        <TABLE width=800 border=0 cellpadding=2 cellspacing=1  valign="top" align="CENTER">
      <TR bgcolor="304A00">
            <TD colspan=4 bgcolor="304A00" align=center><font FACE="verdana,arial,helvetica" size=3 color=B5D083>
            <B>NOTIFICATION OF NEW BAG ORDER</B><BR>
        Order No:<B>#OrderNumber.LastRecord#</B>&nbsp;&nbsp;&nbsp;&nbsp;ORDER TYPE: &nbsp;<B>#ORDERTYPE#</B></font>
            </TD>
      </TR>
        <!--- Ship To --->
      <TR>
          <TD bgcolor="B5D083"><font FACE="verdana,arial,helvetica" size=1>
                  <b>Ship To:</b></font></TD>
          <td bgcolor="white"><font  FACE="verdana,arial,helvetica" size=1>
                  #Shipto1#
            </TD>
          <TD bgcolor="B5D083"><font FACE="verdana,arial,helvetica" size=1>
                  <b>Order Date:</b></font></TD>
          <td bgcolor="white"><font  FACE="verdana,arial,helvetica" size=1>
                  #DateFormat(now(), "mm/dd/yy")#
            </TD>
      </TR>

        ...... more code ......
        </TABLE>

</CFMAIL>
</CFIF>
0
Comment
Question by:sglee
  • 5
  • 2
  • 2
9 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 400 total points
ID: 40521586
do this instead
<cfset bcc = "">
<CFIF "#session.LoginID#" IS '13' or "#session.LoginID#" IS '12'>
<cfset bcc = "user@ABC.com">
</cfif>
 <CFMAIL                  
      FROM="order@ABC.com"
      TO="#session.Email#"
        CC="#Form.Processor#"
        BCC="#bcc#"
      SUBJECT="*#ORDERTYPE#* New Bag Order Notification for Order No:#OrderNumber.LastRecord#" TYPE="HTML">

Open in new window

0
 

Author Comment

by:sglee
ID: 40521631
Ok. I will try that and post the result.
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 100 total points
ID: 40521992
(no points)

I agree with lester, however, I have to comment on the unnecessary quotes and #s..

<CFIF "#session.LoginID#" IS '13' or "#session.LoginID#" IS '12'>

Could be...

<CFIF session.LoginID  eq 13  or session.LoginID  eq 12>  

         ("eq" and "is" are interchangeable; often people use eq for numbers and "is" for strings as a kind of standard, whichever you prefer will work)

or check a list...

<CFIF listFInd("12,13", session.LoginID)>
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:sglee
ID: 40522006
@gdemaria
Thanks for pointing those out and I will definitely use LISTFIND function.
0
 

Author Comment

by:sglee
ID: 40522697
@Jester - The code on ID: 40521586 works just fine. Thank you.
@gdemaria - LISTFIND worked fine. Thank you.
0
 

Author Comment

by:sglee
ID: 40522700
@gdemaria
In <CFIF listFInd("12,13", session.LoginID)> , you removed # signs around Session.LoginID.
Is that normal?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40522718
>  you removed # signs around Session.LoginID.  Is that normal?

Yes, absolutely.  You don't need #s when inside of a CF statement including CFSET, CFIF, CFFUNCTION calls, and all the rest.    The #s are used to identify a CF variable when between CFOUTPUT statements..
0
 

Author Comment

by:sglee
ID: 40522724
Thanks for the information.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 40522857
glad i  could help, thanks for the points
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question