Solved

Changing CFMAIL parameter with CFIF statement in Coldfusion

Posted on 2014-12-28
9
124 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
Comment Utility
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
Comment Utility
Ok. I will try that and post the result.
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 100 total points
Comment Utility
(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
 

Author Comment

by:sglee
Comment Utility
@gdemaria
Thanks for pointing those out and I will definitely use LISTFIND function.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Author Comment

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

Expert Comment

by:gdemaria
Comment Utility
>  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
Comment Utility
Thanks for the information.
0
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
glad i  could help, thanks for the points
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now