?
Solved

Changing CFMAIL parameter with CFIF statement in Coldfusion

Posted on 2014-12-28
9
Medium Priority
?
143 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 1600 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 400 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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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