Skip to content

Function to Bulk delete records from Change request and Incident table #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This background script deletes all records from the incident table having state=7 and urgency=3
This background script also deletes all records from change_request table having priority=3 and impact=2.
It uses the bulkDelete() function to execute the deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function bulkDelete() {

var target = {
'change_request': 'priority=3^impact=2', //conditions for query for the records to be deleted
'incident': 'state=7^urgency=3'
};

for (var table in target) {
if (target.hasOwnProperty(table)) {
var getRecord = new GlideRecord(table);
getRecord.addEncodedQuery(target[table]);
getRecord.query();
var count = 0;
while (getRecord.next()) {

getRecord.deleteRecord();
count++;
}
gs.print("Deleted " + count + " record(s) from " + table + " with query: " + target[table]); //printing count of records
}
}
}
bulkDelete(); //exceuting fuvntion
Loading