Solved

Changing CFMAIL parameter with CFIF statement in Coldfusion

Posted on 2014-12-28
9
133 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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