Skip to content
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,8 @@
This Background will help to bulk update the incident table where
Finds all incidents that are:Active
Have priority 3
Have category = network
Updates each of those records:
Sets state = 2 (which usually means “In Progress”)
Adds a comment: "Updated via bulk update script"
Logs the number of records updated to the system logs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Bulk update function to update records in any table
function bulkUpdate(table, query, data) {
if (!table || !query || typeof data !== 'object') {
gs.error("Invalid parameters provided to bulkUpdate function.");
return;
}

var gr = new GlideRecord(table);
gr.addEncodedQuery(query);
gr.query();

var count = 0;
while (gr.next()) {
for (var field in data) {
if (data.hasOwnProperty(field)) {
try {
gr.setValue(field, data[field]);
} catch (e) {
gs.warn("Failed to set field '" + field + "' on record " + gr.getUniqueValue() + ": " + e.message);
}
}
}
gr.update();
count++;
}

gs.info("Bulk update completed. Total records updated: " + count);
}

// Call the function to update incidents:
// Where active = true, priority = 3, and category = network
bulkUpdate('incident', 'active=true^priority=1^category=Hardware', {
state: 2, // Typically "In Progress"
comments: 'Updated via bulk update script'
});
Loading