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:
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.
Then you can append to the file using FileWrite():
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.