Show Menu
Cheatography

ServiceNow Syntax Editor Macros Cheat Sheet (DRAFT) by

ServiceNow Syntax Editor Macros

This is a draft cheat sheet. It is a work in progress and is not finished yet.

doc

/*════════════════════════════════════════════════════════════════════════════════════════════════════
 ● Description: $0

 ●  Parameters: None

 ●     Returns: None
 ════════════════════════════════════════════════════════════════════════════════════════════════════*/
Docume­ntation Header

gslog

gs.log('['+gs.getUser().getFirstName()+'] '+$0);
gs.log

jslog

jslog("label: " +$0);
jslog

for

for (var i=0; i< myArray.length; i++) {
 //myArray[i]; 
}
Standard loop for arrays

grq

var gr = new GlideRecord("$0");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {
   
}
GlideR­ecord Query

grqor

var gr = new GlideRecord('$0');
var qc = gr.addQuery('field', 'value1');
qc.addOrCondition('field', 'value2');
gr.query();
while (gr.next()) {
 
}
GlideR­ecord Or Query

clientajax

var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_user_name',"Bob");
ga.getXML(HelloWorldParse);
 
function HelloWorldParse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);
}
Client script ajax code

serverajax

var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   helloWorld: function() {
      return "Hello " + this.getParameter('sysparm_user_name') + "!";
   },
 
   _privateFunction: function() { // this function is not client callable     
 
   }
 
});
Server script include ajax code

method

/*════════════════════════════════════════════════════════════════════════════════════════════════════
 ● Description: $0

 ●  Parameters: None

 ●     Returns: None
 ════════════════════════════════════════════════════════════════════════════════════════════════════*/
$0: function() {

},
JavaScript Class Method

stdrun

//set the short description for the workflow
current.short_description = current.short_description+' - '+current.variables.short_description;
current.description = current.variables.description;
'Run Script' code to initialize workflow vars

stdtask

//route to user specified group
task.assignment_group = current.variables.assignment_group;

//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;
Task template