Back to articles
Force records to update sets
There are a few ways to force records to update sets.
Here are three ways how to do it:
Force records to update sets via a simple background script
var tableName = "topic"; // table name
var encodedQuery = ""; // encoded query => the same you have on the list view => "Copy query"
// code
var gr = new GlideRecord(tableName);
gr.addEncodedQuery(encodedQuery);
gr.query();
while (gr.next()) {
var um = new GlideUpdateManager2();
um.saveRecord(gr);
}
Case scenario: add groups that start with an A to update set
Force records to update sets via a UI action
//Commit any changes to the record
current.update();
//Check to make sure the table isn't synchronized already
var tbl = current.getTableName();
if(tbl.startsWith("wf_") || tbl.startsWith("sys_ui_") || tbl == "sys_choice" || current.getED().getBooleanAttribute("update_synch") || current.getED().getBooleanAttribute("update_synch_custom")){
gs.addErrorMessage("Updates are already being recorded for this table.");
action.setRedirectURL(current);
}
else{
//Push the update into the current update set
var um = new GlideUpdateManager2();
um.saveRecord(current);
//Query for the current update set to display info message
var setID = gs.getPreference("sys_update_set");
var us = new GlideRecord("sys_update_set");
us.get(setID);
//Display info message and reload the form
gs.addInfoMessage("Record included in <a href="sys_update_set.do?sys_id=' + setID + '">' + us.name + '</a> update set.");
action.setRedirectURL(current);
}
Case scenario: force a catalog item to be added to update set
This is a nice solution for forcing data or configs that have not been captured in the update set initially.
Force records to update sets via the "Add to Update Set Utility" global UI Action
Case scenario: force any data or config to update set
This is the best solution for adding any record (plus attachments & translations) to the active update set.
Steps for installation:
- Download the XML file (see reference link)
- Import the XML file in your instance
- Navigate to Retrieved Update Sets
- Open the respective update set
- Preview update set
- Commit update set
The "Add to Update Set" app should be set up and you should be able to use this amazing functionality!
You can add stuff to the update set via the Related Link UI action or via a drop-down menu option on each list
Note:
What I noticed is that when you add a record to an update set within an App Scope (in a Scoped update set), the Scoped update set gets automatically copied/duplicated to the Global Scope (as you can see in the image):
For more context check this community question.


The article explains several practical ways to force records into ServiceNow update sets, including a background script and a UI Action. The background-script approach using GlideRecord, an encoded query, and GlideUpdateManager2().saveRecord() is particularly useful when multiple matching records need to be captured efficiently.
ReplyDeleteThe UI Action approach adds another useful workflow by checking whether the table already supports update synchronization before explicitly saving the current record into the active update set. This makes Corporate Javascript Training relevant for understanding the server-side JavaScript, GlideRecord operations, conditions, and scripting patterns involved in ServiceNow customization.
The catalog-item scenario also shows why manually forcing records into update sets can be useful when configuration or data changes are not automatically captured. The combination of update-set handling and reusable scripting techniques provides a practical context for Corporate Javascript Course topics related to JavaScript-based enterprise application customization.
ReplyDelete