The CreatorCon Call for Content is officially open! Get started here.

wanted to forcefully capture the updates for groups related in the update set,

Siva_Prasad
Tera Contributor

hi 

we wanted to forcefully capture the updates for groups related in the update set, is there any background script for it to capture updates forcefully? TIA

regards,
Siva.

 

3 REPLIES 3

ChallaR
Mega Guru

HI @Siva_Prasad ,

 

There are few alterative way to capture but its not good recommendation.

Background Script to Force Capture Group Updates

var updateSetId = 'INSERT_UPDATE_SET_SYS_ID_HERE'; // Replace with your update set sys_id
var gr = new GlideRecord('sys_user_group');
gr.query();
while (gr.next()) {
    var tracker = new GlideRecord('sys_update_xml');
    tracker.initialize();
    tracker.name = gr.getTableName() + '_' + gr.getUniqueValue();
    tracker.target_name = gr.getTableName();
    tracker.target_table = gr.getTableName();
    tracker.update_set = updateSetId;
    tracker.payload = new GlideSysUpdate(gr).getXML();
    tracker.insert();
}

 

  • Replace INSERT_UPDATE_SET_SYS_ID_HERE with the Sys ID of your target update set.
  • This script loops through all sys_user_group records and adds them to the update set.
  • You can modify the query to filter specific groups if needed.

NOTE -

 

  • This method can add a lot of records, so use filters if you only need specific ones.
  • Always test in a sub-production instance before running in production.

Best Practice Alternatives

Instead of using background scripts to force updates:

  1. Use Data Migration Tools:

    • Export/Import XML for specific records.
    • Use Transform Maps or IntegrationHub for structured data migration.
  2. Use Scoped Applications:

    • Package reference data as part of an application with version control.
  3. Document Manual Steps:

    • For static data like groups, document the creation steps and recreate them manually in target instances.
  4. Use the sys_update_set API Carefully:

    • If you must use scripts, ensure you filter records precisely and test thoroughly.

Please mark as correct and close the thread if this is helpful.

Thanks,

Rithika.ch

 

 

suggestion -please use this method unless until its really important to capture .

RaghavSh
Kilo Patron

@Siva_Prasad Refer : https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-add-scheduled-job-script-in... 

 

The answer explains other approaches as well, use the one suitable to you.


Raghav
MVP 2023
LinkedIn