Cheatography
https://cheatography.com
ajax
var ga = new GlideAjax('CLASS_NAME_HERE');
ga.addParam('sysparm_name', 'FUNCTION_NAME_HERE');
ga.addParam('sysparm_PARAMNAME', 'PARAMATER_VALUE');
ga.getXML(callBackParse);
function callBackParse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//insert processing code for answer here
$0
}
|
Inserts the client side ajax code
doc
/*
* DESCRIPTION: Supply a description of this script, function, procedure, class etc.
* NOTES: None
* None
* UPDATES:
* 01/05/16 John Doe Original Version
* 01/15/16 John Doe Fixed screw-ups
*/
|
Documentation header for scripts
for
for (var i=0; i< myArray.length; i++) {
//myArray[i];
}
|
get
var gr = new GlideRecord('$0');
gr.get(sys_id_of_record_here);
//Do something with the record returned
if (gr.category == 'software') {
gs.log('Category is ' + gr.category);
}
|
'Get' Query Shortcut (used to get a single GlideRecord)
getref
$0var caller = current.caller_id.getRefRecord(); //Returns the GlideRecord for the value populated in the 'caller_id' field
caller.email = 'test@test.com';
caller.update();
|
'getRefRecord' Query Shortcut (used to get a single GlideRecord referenced in a reference field)
grq
var gr = new GlideRecord("$0");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {
}
|
GlideRecord Query with optional field parameter
grqor
var gr = new GlideRecord('$0');
var qc = gr.addQuery('field', 'value1');
qc.addOrCondition('field', 'value2');
gr.query();
while (gr.next()) {
}
|
GlideRecord Query with optional field parameter and OR parameter
|
|
gslog
gs.log('VAR=' + $0, 'John Doe');
|
IIFE
Immediately-Invoked Function Expression, or IIFE
method
/*
* Description:
* Parameters:
* Returns:
*/
$0methodName: function(paramOne, paramTwo) {
},
|
JavaScript class method template
stdrun
//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.
//example...
//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.cat_item.name+' - '+current.variables.db+' / '+current.variables.environment;
//current.description = current.short_description;
|
'Run Script' code to initialize workflow variables
stdtask
//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
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets