Skip to main content
Inspiring
September 20, 2009
Question

cfmail questions

  • September 20, 2009
  • 2 replies
  • 4040 views

I have a query where I determine the number of days a request is still open. Here is the partial query :

SELECT DISTINCT 
requestNumber, 
DATEDIFF(day, date_arrived, GETDATE()) + 1 AS daysOpen
email,........

I then use cfmail to send an email to each email address. In the body of the email, I want to break it up into three categories based on the daysOpen

So I have this :

<cfif qry.daysOpen GTE 5 and LT 10>

<cfoutput>display something here in GREEN..etc</cfoutput>

</cfif>

<cfif qry.daysOpen GTE 10 and qrydaysOpen LTE 15>

<cfoutput>display something here in BLUE, etc</cfoutput>

</cfif>

<cffi qry.daysOpen GTE 15>

<cfouput>display somehting here in RED ,etc</cfoutput>

</cfif>

So for each email sent, the recipient show see three outputs, each in a different color.

However, this is not working and only the blue color is showing. I know there are daysOpen for the others also, but everything falls into the blue cateogry,

even daysOpen of 6, which according to the logic, should be green.

What am I doing wrong ? The logic makes sense to me but I guess it is incorrect. What do I need to do to get the three categories ?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    September 20, 2009

    There is one more thing aside from what Adam has said. You almost certainly don't want the qry.daysOpen value of 15 to display blue and red. That line should therefore be something like

    <cfif qry.daysOpen GTE 10 and qry.daysOpen LT 15>

    trojnfnAuthor
    Inspiring
    September 21, 2009

    Sorry, it was getting late and I just tried to retype the pertinent code from memory, thus the typos.

    Here is the actual code that I am using. Again, everything is falling under the category where the days are greater than or equal to 15.

    <cfmail to="#qryGetData.email#"
    cc="xxxxx"
    from="xxxxx"
    subject="Overdue Requests"
    query="qryGetData"
    group="email"
    type="html">

    <style type="text/css">
    body {background: white; color: black; text-align: justify;
          font-family: arial, helvetica, arial, sans-serif; font-size: 10pt;  }
    h2 {font-size: 12pt;  }
    p {text-align: justify;}
    th {font-family: arial, helvetica, arial, sans-serif; font-size: 10pt;}
    td {font-family: arial, helvetica, arial, sans-serif; font-size: 10pt;}
    </style>


    <cfif qryGetData.agedDays GTE 5 and qryGetData.agedDays LT 10>
    <center>
    <table border="1" bordercolor="black" width="600">
    <tr>
    <td class="TitleText" bgcolor="DAA520" colspan="7">Requests that are 5 days or older</td>
    </tr>
    <cfoutput>
    <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
    <td class="TitleText" align="center" width="70"> #qryGetData.request_number#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.agedDays#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.PO_Number#</td>
    <td class="TitleText" align="center" width="180"> #qryGetData.Supplier_Name#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.Part_Number#</td>
    <td class="TitleText" align="center" width="70"> #dollarformat(qryGetData.value_amount)#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.currentState#</td>
    </tr>
    </cfoutput>
    <tr>
    <td class="TitleText" colspan="7">
    Total number of Requests that are 5 days or older: <cfoutput></cfoutput>
    </td>
    </tr>
    </table>
    </center>
    </cfif>


    <cfif qryGetData.agedDays GTE 10 and qryGetData.agedDays LT 15>
    <center>
    <table border="1" bordercolor="black" width="600">
    <tr>
    <td class="TitleText" colspan="7" bgcolor="red">Requests that are 10 days or older</td>
    </tr>
    <cfoutput>
    <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
    <td class="TitleText" align="center" width="70"> #qryGetData.request_number#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.agedDays#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.PO_Number#</td>
    <td class="TitleText" align="center" width="180"> #qryGetData.Supplier_Name#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.Part_Number#</td>
    <td class="TitleText" align="center" width="70"> #dollarformat(qryGetData.value_amount)#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.currentState#</td>
    </tr>
    </cfoutput>
    <tr>
    <td class="TitleText" colspan="7">
    Total number of Requests that are 10 days or older: <cfoutput></cfoutput>
    </td>
    </tr>
    </table>
    </center>
    </cfif>


    <cfif qryGetData.agedDays GT 15>
    <center>
    <table border="0" width="700">
    <tr>
    <td class="TitleText" colspan="7" bgcolor="green">Requests that are 15 days or older</td>
    </tr>
    <tr>
    <td class="TitleText" align="center" width="80"><b>Request</b></td>
    <td class="TitleText" align="center" width="80"><b>Days Opened</b></td>
    <td class="TitleText" align="center" width="80"><b>PO Number</b></td>
    <td class="TitleText" align="center" width="200"><b>Supplier</b></td>
    <td class="TitleText" align="center" width="100"><b>Part Number</b></td>
    <td class="TitleText" align="center" width="80"><b>Value</b></td>
    <td class="TitleText" align="center" width="80"><b>Status</b></td>
    </tr>
    <cfoutput>
    <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
    <td class="TitleText" align="center" width="80">#qryGetData.request_number#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.agedDays#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.PO_Number#</td>
    <td class="TitleText" align="center" width="200">#qryGetData.Supplier_Name#</td>
    <td class="TitleText" align="center" width="100">#qryGetData.Part_Number#</td>
    <td class="TitleText" align="center" width="80">#dollarformat(qryGetData.value_amount)#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.currentState#</td>
    </tr>
    <tr>
    </cfoutput>
    <tr>
    <td class="TitleText" colspan="7">
    Total number of Requests that are 15 days or older: <cfoutput></cfoutput>
    </td>
    </tr>
    </table>
    </center>
    </cfif>

    </cfmail>

    BKBK
    Community Expert
    Community Expert
    September 21, 2009

    You group by email, so your cfmail will be generating rows per email. You can therefore not then try to group by days!

    You will see what actually happens when you do something like this, then restart from there:

    <div align="center">
    <table border="1" bordercolor="black" width="600">
    <cfoutput>
    <cfif qryGetData.agedDays GTE 5 and qryGetData.agedDays LT 10>
        <tr>
        <td class="TitleText" bgcolor="DAA520" colspan="7">Requests that are 5 days or older</td>
        </tr>
       
        <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
        <td class="TitleText" align="center" width="70"> #qryGetData.request_number#</td>
        <td class="TitleText" align="center" width="70"> #qryGetData.agedDays#</td>
        <td class="TitleText" align="center" width="70"> #qryGetData.PO_Number#</td>
        <td class="TitleText" align="center" width="180"> #qryGetData.Supplier_Name#</td>
        <td class="TitleText" align="center" width="70"> #qryGetData.Part_Number#</td>
        <td class="TitleText" align="center" width="70"> #dollarformat(qryGetData.value_amount)#</td>
        <td class="TitleText" align="center" width="70"> #qryGetData.currentState#</td>
        </tr>
        <tr>
        <td class="TitleText" colspan="7">
        Total number of Requests that are 5 days or older: <cfoutput></cfoutput>
        </td>
        </tr>
    </cfif>
    <cfif qryGetData.agedDays GTE 10 and qryGetData.agedDays LTE 15>
        <tr>
        <td class="TitleText" colspan="7" bgcolor="red">Requests that are 10 days or older</td>
        </tr>
    <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
    <td class="TitleText" align="center" width="70"> #qryGetData.request_number#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.agedDays#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.PO_Number#</td>
    <td class="TitleText" align="center" width="180"> #qryGetData.Supplier_Name#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.Part_Number#</td>
    <td class="TitleText" align="center" width="70"> #dollarformat(qryGetData.value_amount)#</td>
    <td class="TitleText" align="center" width="70"> #qryGetData.currentState#</td>
    </tr>
    <tr>
    <td class="TitleText" colspan="7">
    Total number of Requests that are 10 days or older: <cfoutput></cfoutput>
    </td>
    </tr>
    </cfif>
    <cfif qryGetData.agedDays GT 15>
    <tr>
    <td class="TitleText" colspan="7" bgcolor="green">Requests that are 15 days or older</td>
    </tr>
    <tr>
    <td class="TitleText" align="center" width="80"><b>Request</b></td>
    <td class="TitleText" align="center" width="80"><b>Days Opened</b></td>
    <td class="TitleText" align="center" width="80"><b>PO Number</b></td>
    <td class="TitleText" align="center" width="200"><b>Supplier</b></td>
    <td class="TitleText" align="center" width="100"><b>Part Number</b></td>
    <td class="TitleText" align="center" width="80"><b>Value</b></td>
    <td class="TitleText" align="center" width="80"><b>Status</b></td>
    </tr>
    <tr bgcolor="###iif(qryGetData.currentrow MOD 2, DE('FFFFFF'),DE('EEEEEE'))#">
    <td class="TitleText" align="center" width="80">#qryGetData.request_number#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.agedDays#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.PO_Number#</td>
    <td class="TitleText" align="center" width="200">#qryGetData.Supplier_Name#</td>
    <td class="TitleText" align="center" width="100">#qryGetData.Part_Number#</td>
    <td class="TitleText" align="center" width="80">#dollarformat(qryGetData.value_amount)#</td>
    <td class="TitleText" align="center" width="80">#qryGetData.currentState#</td>
    </tr>
    <tr>
    <tr>
    <td class="TitleText" colspan="7">
    Total number of Requests that are 15 days or older: <cfoutput></cfoutput>
    </td>
    </tr>
    </cfif>
    </cfoutput>
    </table>
    </div>

    Inspiring
    September 20, 2009

    <cfif qry.daysOpen GTE 5 and LT 10>

    <cfoutput>display something here in GREEN..etc</cfoutput>

    </cfif>


    And what is LT 10?  I suspect the second part of that statement should read "and qry.daysOpen LT 10".

    <cfif qry.daysOpen GTE 10 and qrydaysOpen LTE 15>

    <cfoutput>display something here in BLUE, etc</cfoutput>

    </cfif>

    Is this - "qrydaysOpen" - a typo in your example, or is it that way in your code too?

    <cffi qry.daysOpen GTE 15>

    <cfouput>display somehting here in RED ,etc</cfoutput>

    </cfif>

    Well "cffi" is definitely not going to compile, so I suspect the code you are citing here is not the code you're actually running.  Because this simply won't run.

    Post your actual code.

    --

    Adam