Is it possible to update the values of a template using a flow designer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 10:21 PM
I am trying to update the value of all standard change templates so that they show model = standard. I have about 500+ templates so it is not viable to do this manually in ServiceNow. Even a background script will be great, the whole idea is to change the template value but when I try dot walking from sys_template table, I am not able to get into the template values.
The only way I have figured out so far is to export the XML and then change values in the XML. Then import them back into ServiceNow but this is also time-consuming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 01:54 AM - edited 04-18-2024 01:55 AM
Hi @Ricky Singh ,
Template values are stored as an encoded query, you can do mass update using script. Please refer below script for your reference:
Sample :
var grr= new GlideRecord('sys_template');
grr.query();
while(grr.next())
{
grr.template += '^active=true';
grr.update();
}
OR
var encodedString = '^u_template_applied_by=javascript:gs.getUserID()^u_template_used=';
var grTem = new GlideRecord('sys_template');
//grTem.addQuery('sys_id', '692c6a13dbd4ef0048f171efbf961983'); // Add more query lines to restrict just to templates that need updating
grTem.addQuery('global', true).addOrCondition('group', '!=', '');
grTem.query();
gs.print(grTem.getRowCount()); // Print out the number of records being updated
while (grTem._next()) {
gs.print(grTem.template);
grTem.template = grTem.template.replace('^EQ', '') + encodedString + grTem.name.toString() + '^EQ';
grTem.setWorkflow(false); // Don't run business rules, etc.
grTem.autoSysFields(false); // Don't update system fields
//grTem.update(); // Un-comment this line once you're sure the row count is just the records you want to update.
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....