Skip to main content
July 25, 2009
Answered

Using cfquery GROUPED output inside CFMAIL

  • July 25, 2009
  • 1 reply
  • 1687 views

Having a problem with displaying grouped CFQUERY results in a CFMAIL. Having researched this issue on these forums and the internet, I found some helpful information, but have been unable to find the answer to my specific issue...

Here's what I'm trying to do. I want to send just one CFMAIL to one user. So far, so good. I'm not using CFOUTPUT in the CFMAIL and it correctly displays CF variables.

The problem is this: I have a CFQUERY that uses the GROUP parameter and I want to display those results all in ONE email. The display works if outside of the CFMAIL:

  <cfoutput query="GetHoliday" group="year">
    <b>#year#</b><br>
    <cfoutput>#DateFormat(holiday,"mm/dd/yyyy")#- </cfoutput><br><br>
   </cfoutput>

The output looks like this:

2010

02/05/2010 - 03/05/2010 - 05/23/2010

2009

06/07/2009 - 07/05/2009 - 08/23/2009

However, inside the CFMAIL it doesn't work. First I took out the CFOUTPUTs and used CFLOOP, but then I can't use the GROUP attribute.

I tried the GROUP attribute on the CFMAIL, but that sends one email per group. I only want one email sent, and the grouped results in that one email as displayed above.

Any ideas on what I'm doing wrong?

Or is there a way to run the group outside the CFMAIL, store in a variable and somehow display it? I'm guessing no since the query is a complex data type...

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    loamguy wrote:

    Any ideas on what I'm doing wrong?

    Or is there a way to run the group outside the CFMAIL, store in a variable and somehow display it? I'm guessing no since the query is a complex data type...

    I do not think you are doing anything wrong. AFAIK, there is no built in method for grouping the mail content exactly that way you described.

    Yes, you could use cfsavecontent to capture the grouped. Then include it in your mail message.

    <cfsavecontent variable="mailContent">
    <cfoutput query="GetHoliday" group="year">
        <b>#year#</b><br>
        <cfoutput>#DateFormat(holiday,"mm/dd/yyyy")#- </cfoutput><br><br>
    </cfoutput>
    </cfsavecontent>

    <cfmail to="somebody@place.com" from="somebody@place.com" subject="Holidays">
        #mailContent#
    </cfmail>

    1 reply

    -__cfSearching__-Correct answer
    Inspiring
    July 25, 2009

    loamguy wrote:

    Any ideas on what I'm doing wrong?

    Or is there a way to run the group outside the CFMAIL, store in a variable and somehow display it? I'm guessing no since the query is a complex data type...

    I do not think you are doing anything wrong. AFAIK, there is no built in method for grouping the mail content exactly that way you described.

    Yes, you could use cfsavecontent to capture the grouped. Then include it in your mail message.

    <cfsavecontent variable="mailContent">
    <cfoutput query="GetHoliday" group="year">
        <b>#year#</b><br>
        <cfoutput>#DateFormat(holiday,"mm/dd/yyyy")#- </cfoutput><br><br>
    </cfoutput>
    </cfsavecontent>

    <cfmail to="somebody@place.com" from="somebody@place.com" subject="Holidays">
        #mailContent#
    </cfmail>

    July 25, 2009

    And that did the trick!! Thanks very much--that was driving me nuts. Cheers!