Search code examples
coldfusioncoldfusion-8

Coldfusion 8 how do I get a data log in a cfscript tag?


So I have a cfscript tag that runs some XML data through but I'm getting an error on one of my executes its getting weird data it cant use, I am trying to find out what this data is however, all of my attempts to cfdump this data have failed miserably. Does anyone know of a way to get a data log from inside cfscript data?

I've tried:

  • -Ending the script writing the dump and restarting the script

  • -ending the script writing the dump and aborting

  • -putting the dump at the end of the cfscript

    I'm running out of ideas. Thank you ahead of time!


Solution

  • Here's are my tips:

    First, create a UDF in tag format - I call my "sdump":

    <cfunction name="sdump">
         <cfargument name="anyvar" required="true"/>
         <cfdump var="#anyvar#"/>
    </cffunction>
    

    Then in your cfscript while debugging you can simply do:

    <cfscript>
    
    sdump(myProblemobject);
    </cfscript>
    

    That keeps you from having to break your script block all the time. I actually include mine in a CFC library of functions that's loaded in Onrequest.

    Second, sometimes cfdump doesn't play nice with complex XML. It's gotten really smart in CF 9 and later, but I remember CF8 not always loving complicated XML. In that case you have to use your noggin.

    For example, try using toString() on the XML object itself and dumping it in source as in tmpvar = toString(myXml); This is more useful if you split out the specific node that is causing you problems into it's own little xml object. Then use dump or (if dump fails) try "writeoutput();" - which is made like a cfoutput for cfscript - like so:

    <cfscript>
       xmlTmp = toString(myXml);
       writeoutput(xmlTmp);
    </cfscript>
    

    Working your way through the xml attribute by attribute and node by node might be tediuous, but it might be easier than walking your eyballs through the raw XML looking for issues.

    Remember too that you can validate your XML document or var using the various isXML() functions native to CF (isXML(), isXMLAttribute() etc.). Not sure what the list looked like in CF8. Good luck - these sort of problems are always trial and error I'm afraid. :)