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:
  1. Download the XML file (see reference link)
  2. Import the XML file in your instance
  3. Navigate to Retrieved Update Sets
  4. Open the respective update set 
  5. Preview update set
  6. 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):



As weird as it may look this still will work when you migrate the Batch Update Set or the individual Global update set to another instance.

For more context check this community question.



Comments

  1. 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.

    The 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.

    ReplyDelete
  2. 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

Post a Comment

Popular Posts