Sending a Variable Dump in Cfscript Mail for ColdFusion 9

Posted: February 22, 2011 in ColdFusion

Recently I had an issue with a variable that I needed to take a look into. Many times I just mail myself a Cfdump of the variable. Today I tried it completely Cfscript-wise and failed with a “Method writeDump with 1 arguments is not in class coldfusion.runtime.CFComponent.” error. This is what I tried:

local.testVar = 'test';

local.mailerService = new mail();
local.mailerService.setTo('bogus@domain.xyz');
local.mailerService.setFrom('bogus@domain.xyz');
local.mailerService.setSubject('Heres your var dump');
local.mailerService.setType('html');
local.mailerService.send(body=writeDump(local.testVar));

I even tried writing it to a variable (assuming this would fail):

local.testVar = 'test';
local.testDump = writeDump(local.testVar);

local.mailerService = new mail();
local.mailerService.setTo('bogus@domain.xyz');
local.mailerService.setFrom('bogus@domain.xyz');
local.mailerService.setSubject('Heres your var dump');
local.mailerService.setType('html');
local.mailerService.send(body=local.testDump);

But that just failed with the same error on the second line above.

I really couldn’t find anything on this in Google, but after manipulating my keywords for awhile, I ran across a blog with a code sample that seems to accomplish what I needed. The key was to run “savecontent” as save the contents off into a variable:

local.testVar = 'test';
savecontent variable="local.testDump" {
writeDump(local.testVar)
}

local.mailerService = new mail();
local.mailerService.setTo('bogus@domain.xyz');
local.mailerService.setFrom('bogus@domain.xyz');
local.mailerService.setSubject('Heres your var dump');
local.mailerService.setType('html');
local.mailerService.send(body=local.testDump);

Now before you say why would I dump a string, I was actually trying to dump a query result.

On a side-note, feel free to come to the Nebraska ColdFusion Users Group tonight and learn neat things like this!

Advertisements
Comments
  1. Chris H says:

    Hey, thanks for this info, that same problem was driving me crazy the last few days…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s