Example usage

The deleteMultiple() method can be called either after the query(), or without it, but without calling next():

var query = 'active=false^closed_atRELATIVELT@year@ago@2'; //Tickets closed more than 2 years ago 
var gr = new GlideRecord('incident');
gr.addQuery(query);
gr.deleteMultiple();

In this case, I'm running this on the Incident table, which in my instance does not have any currency fields. Again, this method should not be called on any tables that contain currency fields due to a limitation in ServiceNow. Instead, use the following deleteRecord() syntax:

var query = 'active=false^closed_atRELATIVELT@year@ago@2'; //Tickets closed more than 2 years ago 
var gr = new GlideRecord('incident');
gr.addQuery(query);
gr.query();
while (gr.next()) {
gr.deleteRecord();
}

Both of these blocks of code will delete all records matching the encoded query stored in the query variable, which pulls a list of all incidents that are not active, and which were closed more than two years ago, as you might see if a company wants to retain records for two years and then delete them to keep the Task [task] table light.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.249.104