I need a way to apply a template to change record in background with template sys_id rather than template Name

sanju41
Giga Contributor

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

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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.


View solution in original post

5 REPLIES 5

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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.