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!