SN TRICK: To capture any record in current update set without having 'Add to update set' utility

Animesh Das2
Mega Sage

 

🖊📖...TRICK_AD_104...

Many a times we feel the need of capturing a record or to recapturing something in an update set.

 

According to the OOB functionalities, anything that does not have 'update_synch=true'  in the dictionary('sys_dictionary') attribute does not get captured in the update set automatically. This 'update_synch=true'  is managed by ServiceNow itself in the backend. We should not touch this attribute to avoid any unwanted issues in future.

 

Don't worry, here we have something to capture those kind of staffs in the current update set by executing a simple script in the background script.

 

For example, please follow the below steps to capture a record(any table) of 'sys_dictionary' table. (Records in 'sys-dictionary' gets automatically captured in update set OOB but I am taking this example in case we need to recapture in another update set for some specific reason.)

 

Step 1: Create an update set in the same scope, here in this case it should be global only, and make the update set as current.

Step 2: Run the below script in background script.

var dictionaryRecords = new GlideRecord('sys_dictionary');

dictionaryRecords.addQuery('nameIN<your table_name>'); //Using 'IN' operator in case you have multiple table records to capture

dictionaryRecords.query();

while (dictionaryRecords.next()) {

    gs.updateSave(dictionaryRecords);

}

Step 3: All set! now you can verify the customer update in the update set and you would see the record is there in the update set.

 

Note: gs.updateSave() can push any record to the update set even those that are not marked as update_sync=true. The code can be modified and used as per need. 🖋📔😊

 

Thanks, 

Animesh Das

Happy learning and sharing!

You may mark this helpful as well if it helps you.

1 REPLY 1

Nehal Dhuri
Mega Sage

Thank you for sharing this trick!
It’s something new I learned today, really appreciate it 😄

Please hit like and mark my response as correct if that helps