Pete Freitag Pete Freitag

Top 10 Underrated Functions in ColdFusion

Updated on December 07, 2023
By Pete Freitag
coldfusion

I gave a presentation at my local CFUG yesterday called 10 Underrated Functions in ColdFusion, I plan on doing one for tags as well at some point. Here was my list of functions, in no particular order:

  • ValueList - Returns the contents of an entire query column in a string list.
  • ExpandPath - Returns a server file path relative to the calling template.
  • Hash - Encodes a string using MD5, or in CFMX 7 you can specify any hashing algorithm such as SHA.
  • RandRange - Returns a random number bound by two integers.
  • XmlFormat - Escapes special characters in XML, and can also be used to prevent cross site scripting attacks.
  • IsValid - Validates that a string is in the specified format (email, ssn, integer, etc).
  • GetMetricData - Gives server metrics, like average request time, etc.
  • ToScript - Serializes a ColdFusion variable into JavaScript or ActionScript
  • GetPageContext - Gets the JSP PageContext object. Can be used to include JSP files in a CFM page, and more.
  • XmlSearch - Search an XML document using an XPath Query

Did I have any obvious omissions? What would be on your list?



functions cfml coldfusion valuelist expandpath hash randrange xmlformat isvalid getmetricdata toscript getpagecontext xmlsearch xpath cfug

Top 10 Underrated Functions in ColdFusion was first published on January 10, 2007.

If you like reading about functions, cfml, coldfusion, valuelist, expandpath, hash, randrange, xmlformat, isvalid, getmetricdata, toscript, getpagecontext, xmlsearch, xpath, or cfug then you might also like:

Fixinator

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community


Comments

There are a LOT of functions that I think are underrated - in fact, I think all built-in functions are overlooked at one point or another. I honestly have been meaning to re-read the function reference to remind myself of some of the gems out there.
by todd sharp on 01/10/2007 at 9:05:04 AM UTC
I'm always amazed whenever I see someone manually implement code to do what listQulify() or listChangeDelims() does.
by Brian Kotek on 01/10/2007 at 9:29:34 AM UTC
IsValid() is one of the best functions ever
by TJ Downes on 01/10/2007 at 9:50:29 AM UTC
A few:

incrementValue/decrementValue: If you don't need to keep the result, this is handy in urls, for example, linking ot the next page.

isDebugMode - add your own debug stuff (I need to blog this)

A big amen on isValid. I think it is probably the least known cool feature of CF7.
by Raymond Camden on 01/10/2007 at 9:54:23 AM UTC
ArrayToList() and ListToArray() would have to be one that I see implemented in other ways frequently.
by Ryan Guill on 01/10/2007 at 9:54:32 AM UTC
Brian - what about manual implementations of fileExists() or directoryExists()? I'm guilty of those (a long time ago ;)
by todd sharp on 01/10/2007 at 9:55:07 AM UTC
"I'm always amazed whenever I see someone manually implement code to do what listQulify() or listChangeDelims() does."

I'm even more amazed that I still do it from time to time =)
by Sam on 01/10/2007 at 10:01:55 AM UTC
Forgot to subscribe.
by todd sharp on 01/10/2007 at 10:09:49 AM UTC
They may not be under-rated but I find that val() and htmleditformat() are often overlooked in securing templates from incoming POST/GET data.
by JAlpino on 01/10/2007 at 11:12:00 AM UTC
I'm with Brian on ListQualify. That's a hidden gem from 4.01 that it seems many missed (and continue to do).
Great list, Pete. Thanks for sharing.
by Charlie Arehart on 01/10/2007 at 11:19:10 AM UTC
What about urlEncodedFormat() and urlDecode() - I've seen manual workarounds to these before.
by todd sharp on 01/10/2007 at 11:25:57 AM UTC
Mine would probably be monthAsString in combination with setLocale(), coming from the Netherlands (in other words a non-english speaking/reading country) i still see a lot of developers making a list with the locale names of the months and then a loop with 1 to 12 and getting the correct name :-)

monthAsString(month(now())) would do the trick.. also for days. Much overlooked function. LSDateFormat(now(),'mmmm') would also do it.
by Tjarko Rikkerink on 01/10/2007 at 2:45:42 PM UTC
XmlFormat() is kinda the suck, it does not parse xml all the time correct. I know its sloppy but I have been to busy to combine the 2 udf's but these in tandem will format anything in xml
http://www.cflib.org/udf.cfm?ID=999 and http://www.cflib.org/udf.cfm?ID=572
by Oliver on 01/10/2007 at 4:22:01 PM UTC
Oliver,

I'd love to see an example of where XmlFormat doesn't work. I haven't had any problems with it, not to say there aren't - I'd just like to see first hand.
by Pete Freitag on 01/10/2007 at 4:29:01 PM UTC
Just to go along with value list, there's the little used QuotedValueList() which does the same thing as ValueList() but puts quotes around each list item (like ListQualify() with quotes).
by Ben Nadel on 01/10/2007 at 7:18:30 PM UTC
xmlFormat is VERY broken. I've had numerous issues with it on BlogCFC where xmlFormat would let characters by (like MS Extended chars) that mess up valid XML.
by Raymond Camden on 01/10/2007 at 7:48:25 PM UTC