Skip to content

Commit d5fd0df

Browse files
authored
Fix script to clean up and update multiple records errors (#1715)
* Create README.md * Create update_multiple_records.js * Create update_multiple_records_v2.js * Update update_multiple_records_v2.js * Update update_multiple_records.js * Update README.md
1 parent 8532d69 commit d5fd0df

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//This Fix scripts is to clean up multiple record errors
2+
// Navigate to Scripts-Background
3+
// Past the script and update the place holder variable value: table name, field, and value etc.
4+
// Also advisable to validate the row count the //gr.getRowCount() and remove from codebase.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var GrQry = ""; //Query of the affected records.
2+
3+
var grTableName = new GlideRecord('table_name');
4+
grTableName.addEncodedQuery(GrQry);
5+
grTableName.query();
6+
{
7+
grTableName.setValue("field", "value"); // Replace 'field' and 'value'
8+
grTableName.autoSysFields(false); // Prevents updating system fields like 'updated by'
9+
grTableName.setWorkflow(false); // Prevents triggering workflows
10+
grTableName.updateMultiple();
11+
}
12+
gs.print("Records updated successfully");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var GrQry = ""; //Query of the affected records.
2+
3+
var grTableName = new GlideRecord('table_name');
4+
grTableName.addEncodedQuery(GrQry);
5+
grTableName.query();
6+
7+
while (grTableName.next()) {
8+
grTableName.setValue("field", "value"); // Replace 'field' and 'value'
9+
grTableName.autoSysFields(false); // Prevents updating system fields like 'updated by'
10+
grTableName.setWorkflow(false); // Prevents triggering workflows
11+
grTableName.update();
12+
}
13+
gs.print("Records updated successfully");

0 commit comments

Comments
 (0)