Apply template to inc using Scheduled Jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 11:06 PM - edited 04-14-2024 11:38 PM
Hi All
So I have this running every 20secs
var templateGr = new GlideRecord('sys_template');
templateGr.get('93114dcec3250210c6b0bbec050131d3');
if (templateGr.isValidRecord()) {
var targetRecord = new GlideRecord('incident');
targetRecord.get('8d6353eac0a8016400d8a125ca14fc1f');
if (targetRecord.isValidRecord()) {
templateGr.apply(targetRecord);
targetRecord.update();
gs.info('Template applied and incident updated');
} else {
gs.error('Incident not found');
}
} else {
gs.error('Template not found');
}
Problem is nothing happens. I get a log saying "Template applied and incident updated" but nothing is updated on the inc.
I know the template and inc sys_id are found because the script would error
The template works. I can apply it manually.
table in incident
domain is global
user is system administrator
nothing in groups
global is ticked
Thanks
Andrew
Note:
Got it to work:
targetRecord.applyTemplate("20_min_awiting_user");
targetRecord.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 07:43 AM
You could try using '"applyTemplate" to your "targetRecord" instead of ".apply". More info can be found here: https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/form-adminis...