xplore scripts
used in servicenow
basic script
var count = 0;
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
count++;
gr.update();
}
gs.log('count: ' + count);
gr
Useful commands:
gr.deleteRecord();
gr.addQuery('active',false);
gr.addNotNullQuery('short_description');
Create a new record:
gr.initialize();
gr.insert();
Count records in a query:
var gr = new GlideRecord('elements');
gr.addQuery('hierarchy', 'sys_id');
gr.query();
gs.log('Incident count: ' + gr.getRowCount());
gr
gr.addQuery('hierarchy', 'sys_id');
gr.query();
gs.log('Incident count: ' + gr.getRowCount());
gr