Show Menu

Personal ServiceNow Syntax Macros Cheat Sheet by


var ga = new GlideAjax('CLASS_NAME_HERE');
ga.addParam('sysparm_name', 'FUNCTION_NAME_HERE');
ga.addParam('sysparm_PARAMNAME', 'PARAMATER_VALUE');

function callBackParse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');

//insert processing code for answer here

Inserts the client side ajax code


 * DESCRIPTION: Supply a description of this script, function, procedure, class etc.
 * NOTES: None
 * None
 * 01/05/16 John Doe Original Version
 * 01/15/16 John Doe Fixed screw-ups
Docume­ntation header for scripts


for (var i=0; i< myArray.length; i++) {


var gr = new GlideRecord('$0');
//Do something with the record returned
if (gr.category == 'software') {
   gs.log('Category is ' + gr.category);
'Get' Query Shortcut (used to get a single GlideR­ecord)


$0var caller = current.caller_id.getRefRecord(); //Returns the GlideRecord for the value populated in the 'caller_id' field = '';
'getRe­fRe­cord' Query Shortcut (used to get a single GlideR­ecord referenced in a reference field)


var gr = new GlideRecord("$0");
gr.addQuery("name", "value");
if ( {
GlideR­ecord Query with optional field parameter


var gr = new GlideRecord('$0');
var qc = gr.addQuery('field', 'value1');
qc.addOrCondition('field', 'value2');
while ( {
GlideR­ecord Query with optional field parameter and OR parameter


gs.log('VAR=' + $0, 'John Doe');


(function () {
Immedi­ate­ly-­Invoked Function Expres­sion, or IIFE


* Description:
* Parameters:
* Returns:
$0methodName: function(paramOne, paramTwo) {

JavaScript class method template


//Code to insert in a Run Script step.
//The below sets the RITM short_description & description values with sample fields from the Catalog Item variables.
//You can copy from a catalog item form field or fill with your own description.
//"stdtask" syntax editor macro could follow in a CATTSK populating the short_description & description from the RITM values assigned here.
//REF: "stdtask" syntax editor macro.

//set the short description for the workflow
//current.short_description = current.short_description+' - '+current.variables.short_description;
//current.short_description = current.variables.request_type.getDisplayValue()+' - '+current.short_description; //get a form value example
current.description = current.variables.description; //set the description equal to the short_description

//another example...
//set the short_description & description on the RITM
current.short_description =' - '+current.variables.db+' / '+current.variables.environment;
//current.description = current.short_description;
'Run Script' code to initialize workflow variables


//Code to insert in a CATTSK
//The below sets the CATTSK due_date, short_description & description values.
//It copies the values from the RITM values which would work in concert with the UI Macro "strrun"
//"stdrun" would previously have populated the RITM from the Catalog Item variables.
//REF: "stdrun" syntax editor macro.

//set the task due date to the request item due date
task.due_date = current.due_date;

//set the short description to match the requested item
task.short_description = current.short_description;

//set the description to match the requested item description
task.description = current.description;
Script code to populate the CATTSK with RITM values

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          PHP Syntax for beginners Cheat Sheet
          C Reference Cheat Sheet