On Null

I'm finally doing a lot of work with CF 9's ORM and I'm finding that dealing with null values in CFML can be quite a pain, especially when working with relationships. One thing that comes up quite a bit is iterating over child collections. ColdFusion goes out of it's way to shield developers from null values, yet when an entity has an empty collection ColdFusion returns a null. (Long time user of CFML would likely expect an empty array here, similar to how <cfquery> returns and empty string for null values, but this is not the case.) This means I end up doing something like this quite a bit:

[More]

Quick Tip: cffile action=”append” in cfscript

So this is old news - like ColdFuison 8 old news - but I've only started to use cfscript heavily with ColdFusion 9 so I just ran into this today. If you need to append to a file in cfscript you first need to use FileOpen() to open a file object in the append mode.

fileObj = FileOpen("/path/to/myfile.txt","append");

Then you can append to the file using FileWrite():

FileWrite( fileObj, "What ever is here gets appended.");

Note that unlike the default behavior of <cffile action="append"> FileWrite() does not append a newline character to text written to file.

Appending to a file isn't documented on the FileWrite() documentation for either ColdFusion 8 or ColdFuison 9, and the documentation does not list FileOpen() in the See Also section, so this took me a lot longer to figure out than it should have. Anyway, I hope this helps others making the transition from tag based to script based CFML.

BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.