From c8da861e02bce8ab4f747961a9a17e459d027c50 Mon Sep 17 00:00:00 2001 From: Soumyadeep10 <78016846+Soumyadeep10@users.noreply.github.com> Date: Sat, 26 Oct 2024 13:04:11 +0530 Subject: [PATCH 1/2] Create bultDeleterecords_Soumyadeep.js This background script deletes all records from the incident table having state=7 and urgency=3 as well as from change_request table for records having priority=3 and impact=2. --- .../bultDeleterecords_Soumyadeep.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/bultDeleterecords_Soumyadeep.js 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 From badfb99a3a7022771b977aee7e1d7088641cf51d Mon Sep 17 00:00:00 2001 From: Soumyadeep10 <78016846+Soumyadeep10@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:03:04 +0530 Subject: [PATCH 2/2] Create Readme_Soumyadeep.md 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. --- .../Readme_Soumyadeep.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Background Scripts/Bulk Delete Records in Multiple Tables with Conditions/Readme_Soumyadeep.md 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.