Write dump in cfmail with cfscript in ColdFusion

by 9:14 AM 6 comments
I find it handy to dump out a scope and email it to myself. I use this occasionally in Application.cfc in onError() or onMissingTemplate() to dump cgi and the exception variables.

This weekend I was working on a small ColdFusion project and am using cf9. All my cfc's are in script and I wanted to dump full scopes and email them back to myself. Its not as simple as in tags but its a workable solution using savecontent.

I really expected this to just work:

mail.addPart( type="html", charset="utf-8", body=writedump(application) );

But it wont so here is the solution:

Here is the solution:



The other exception to my project was one cfc had to have a udf for cfexecute which also is not yet in cfscript.


Update.

To answer Steves question here is the code example.

You can just attach the report as a file attachment and specify the content.

Paul Kukiel

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

6 comments:

  1. hmm,
    I haven't used a lot of cfscript because my access to cf9 is limited but it seems to me that savecontent variable="tmpVariable" {
    writedump(application);
    }
    would have been something more along the lines of
    tmpVariable = savecontent({writedump(application)});

    I guess it's more inline with the tagged version but doesn't seem to follow a more standard script syntax. Thanks for the post.

    ReplyDelete
  2. @Paul -

    This is good stuff. I haven't had an opportunity yet to play with the scripted cfmail. One thing to note though. I too like to dump values into my error reports, sometimes multiple items. That said, GMail (and a few others) will prevent messages over a certain size (and the cfdump stuff has a lot of overhead). In that case you can attach your dump output to the mail message, as outlined in Ben Nadel's article:

    http://www.bennadel.com/blog/1649-Attaching-ColdFusion-Error-Reports-To-Avoid-GMail-Spam.htm

    What would it take to convert Ben's example to a script format?

    ReplyDelete
  3. @Steve

    Sure it can be done. I have added an update to the post to include the code to send the report an attachment.

    ReplyDelete
  4. You have spelled 'its' wrongly.

    ReplyDelete
  5. One bug I noticed was the BCC on the script. It did not work properly and threw an error when trying to add that portion of the code. Not sure why it is shown on several examples throughout me code search, but when I tried utilizing it, it did not work properly. I notice you do not have it on your example either.

    Have you tried implementing it?

    ReplyDelete