GlideRecord

GlideRecord Cheat Sheet


Query

      
var grInc = new GlideRecord('incident');
grInc.addQuery('active', true);
grInc.query();

while(grInc.next()) {

            gs.info('Category is ' + grInc.category);

}


Get

      
var grInc = new GlideRecord('incident');

if (grInc.get('sys_id')) {

   gs.info('Category is ' + grInc.category);

} else {

    gs.info('Record not found.');

}


Or
      Or conditions can be stacked orGr.addOrCondition('state', 6).addOrCondition('state', 7);

 
var grInc = new GlideRecord('incident');
var orGr = grInc.addQuery('state', 6);
orGr.addOrCondition('state', 7);
grInc.query();

while(grInc.next()) {

            gs.info('Category is ' + grInc.category);

}


Insert

      
var grInc = new GlideRecord('incident');
grInc.initialize();
grInc.short_description = 'This is the short description';
grInc.description = 'This is the description of my new record.';
grInc.insert();

Update

      
var grInc = new GlideRecord('incident');

if (grInc.get('sys_id')) {

   grInc.short_description = 'This is the new short description';
   grInc.setWorkflow(false); //Disable business rules for this query
   grInc.autoSysFields(false); //Disable the update of system fields
   grInc.update();

}

Delete

      
var grInc = new GlideRecord('incident');

if (grInc.get('sys_id')) {

    grInc.deleteRecord(); //Delete the record

}



      And below we have a list of operators we can use with the addQuery() method.


Operators



Back