Skip to content

Commit 4bcf607

Browse files
Create BG Scripts - Bulk Update Tables.js
This Background script will help to bulk update the Incident table if condition match
1 parent d5e58c8 commit 4bcf607

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function bulkUpdate('incident', 'active=true^priority=3',) {
2+
if (!table || !query || typeof data !== 'object') {
3+
gs.error("Invalid parameters provided to bulkUpdate function.");
4+
return;
5+
}
6+
7+
var gr = new GlideRecord(incident);
8+
gr.addEncodedQuery(query);
9+
gr.query();
10+
11+
var count = 0;
12+
while (gr.next()) {
13+
for (var field in data) {
14+
if (data.hasOwnProperty(field)) {
15+
try {
16+
gr.setValue(field, data[field]);
17+
} catch (e) {
18+
gs.warn("Failed to set field '" + field + "' on record " + gr.getUniqueValue() + ": " + e.message);
19+
}
20+
}
21+
}
22+
gr.update();
23+
count++;
24+
}
25+
26+
gs.info("Bulk update completed. Total records updated: " + count);
27+
}

0 commit comments

Comments
 (0)