CFSCRIPT Snippets and Hints

Some useful cfscript snippets and syntax. Many of these originated from Pete Freitag's CFSCRIPT Cheat Sheet: https://www.petefreitag.com/cheatsheets/coldfusion/cfscript/

Transaction Integrity Protection

Instructs the database management system to treat multiple database operations as a single transaction. Provides database commit and rollback processing.

transaction {
	//do stuff
	if (good) {
		transaction action="commit";
	} else {
		transaction action="rollback";
	}
}

Loops

Simple Loop

for (i=1;i LTE ArrayLen(array);i=i+1) {
	WriteOutput(array[i]);
}

While Loop

Do / While Loop

For / In Loop

The for/in loop can be used to loop through queries, structures, or arrays

If / Then / Else

Switch Statement

Comments

Comments are done the same way a JavaScript: use // for single line comments and /* */ to encompass multi-line comments. Do not use CFML comment markers: <!--- --->

Try / Catch / Throw

Last updated

Was this helpful?