diff --git a/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/Readme_Soumyadeep.md b/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/Readme_Soumyadeep.md new file mode 100644 index 0000000000..8b9803c9ed --- /dev/null +++ b/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/Readme_Soumyadeep.md @@ -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. diff --git a/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/bultDeleterecords_Soumyadeep.js b/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/bultDeleterecords_Soumyadeep.js new file mode 100644 index 0000000000..97a6373139 --- /dev/null +++ b/Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/bultDeleterecords_Soumyadeep.js @@ -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