- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:24 PM
Example : var ga= new GlideRecord("change_request");
ga.applyTemplate("Name of template") ;
ga.insert();
I need a way to apply template with sys_id of template rather than template name
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:56 PM
It's undocumented, but I have seen this code in Event Managemt business rule where you can apply a template via SysId using the following syntax:
GlideTemplate.get(template.sys_id).apply(GlideRecord)
Set the Sys_ID in the first parameter and the record you want to apply it to in the apply function. This has saved me a headache or two in the recent past.
Please mark helpful or correct if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:33 PM
http://wiki.servicenow.com/index.php?title=GlideRecord#applyTemplate&gsc.tab=0
The function only takes a name. But you can get the name via the sys_id.
var templateID = '3d5fa670dbdd2a00bd3cff9dbf96195c';
var templateName = '';
var template = new GlideRecord('sys_template');
if (template.get(templateID)) {
templateName = template.name;
}
var chg = new GlideRecord("change_request");
chg.applyTemplate(templateName) ;
chg.insert();
I should also point out that hard-coding sys_ids is considered bad-practice and will be flagged in an ACE report.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:38 PM
Are you applying the Template to every change? If so you can modify the module to include the template.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:54 PM
No, i need to apply a template in Workflow for one Service request which create's a create record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 05:55 PM
*Change record