Cheatography
https://cheatography.com
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
════════════════════════════════════════════════════════════════════════════════════════════════════*/
|
gslog
gs.log('['+gs.getUser().getFirstName()+'] '+$0);
|
for
for (var i=0; i< myArray.length; i++) {
//myArray[i];
}
|
grq
var gr = new GlideRecord("$0");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {
}
|
grqor
var gr = new GlideRecord('$0');
var qc = gr.addQuery('field', 'value1');
qc.addOrCondition('field', 'value2');
gr.query();
while (gr.next()) {
}
|
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);
}
|
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() {
},
|
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;
|
|