Apply Template UI Action

rosasmig
Kilo Contributor

Everyone,

I need to apply a specific template on and

I ´m trying to use the applyTemplate method by using a GlideRecord variable, and initialize it after declaring it   but it is not working any ideas?

Got information from Scripted templates

see bellow:

Onclick: btemps

function () btemps {

var rec1 = new GlideRecord("incident");

rec1.initialize();

rec1.applyTemplate("my_incident_template");

}

--

Thanks

Miguel

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

That is the code to apply templates is server side and won't work on a client side UI action.


The code you have given is client side; current.applyTemplate will not work. There is also some syntax issues.



The code below should work for you



function   btemps () {


        applyTemplate(sys_id_of_my_incident_template);


}



Apply Template on Field Change — ServiceNow ELITE.com



Just a heads up - similar functionality to what you are asking for is available in Geneva.


There is a new Template bar at the bottom of each form and you can click on any template from there to populate the form.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

4 REPLIES 4

The SN Nerd
Giga Sage
Giga Sage

That is the code to apply templates is server side and won't work on a client side UI action.


The code you have given is client side; current.applyTemplate will not work. There is also some syntax issues.



The code below should work for you



function   btemps () {


        applyTemplate(sys_id_of_my_incident_template);


}



Apply Template on Field Change — ServiceNow ELITE.com



Just a heads up - similar functionality to what you are asking for is available in Geneva.


There is a new Template bar at the bottom of each form and you can click on any template from there to populate the form.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hey Paul, it worked as expected.. it ´s kind of tricky to know when you need to add sys_ids ´s to methods so they work..


Thanks for your help!!


Found your link really helpful for my simple task of trying to apply a template based on subcategory.



Thank you!


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Miguel,



You may find the below thread helpful.


http://www.servicenowguru.com/system-definition/advanced-templates/