Create template through UI Action

sncrnd
Kilo Contributor

Hi All

How i can create template thought UI Action( Create template) on incident form, i got help from SNCGURU( » Advanced Templates) . it's really helpful but my requirement is different.

what i need.

Suppose you are opening existing record   on incident and you want to create new template   so you personalize form and clicking on Template Option-> Save as template,

Example.

template.PNG

Same thing i want to create through UI Action

Means make custom UI Action and same functionality use as Save as template.

Please help if you have any idea,and let me know.

Thanks

C.K

2 REPLIES 2

Slava Savitsky
Giga Sage

ServiceNow templates store all field-value pairs that need to be applied to the target record in the Template field in the form of an encoded query which is basically a sting like this:



active=true^priority=1^category=incident



You can create a UI action that will:


  1. read field values from the current record
  2. build an encoded query similar to the one above
  3. insert a new record into Templates [sys_template] table using GlideRecord API

Mlombardo
Kilo Expert

Hi C.K.




Here is an example UI action I started for change in case you are still stuck:



CreateChangeTemplate();




function CreateChangeTemplate() {


  var temp = new GlideRecord('sys_template');


  var ci = current.cmdb_ci;


  var assgroup = current.assignment_group;


  var cat = current.cateogry;


  var shortd = current.short_description;


  var reason = current.u_reason_for_change;



  temp.initialize();


  temp.table = ('change_request');


  temp.template = 'cmdb_ci=' + ci + '^assignment_group=' + assgroup + '^category=' + cat + '^short_description=' + shortd + '^u_reason_for_change=' + reason;


  temp.insert();


 



}