Solved

Changing CFMAIL parameter with CFIF statement in Coldfusion

Posted on 2014-12-28
9
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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