The CreatorCon Call for Content is officially open! Get started here.

How to insert record to the sys_template table?

JLeong
Mega Sage

Hi!

How can I insert a template record into the sys_template table via script?

Data is coming from a Service Catalog request. I've started but not sure how to proceed to insert template information.

var rec = new GlideRecord('sys_template');

rec.initialize();

rec.table = 'incident';

rec.name = current.variable_pool.inc_temp_name;

rec.short_description = current.variable_pool.inc_temp_short_desc;

// --- Template --//

rec.insert();

Thanks!

Jocelyn

1 ACCEPTED SOLUTION

If what you want to do is put the value entered in variables inside of the template field, you would need to go with something along the lines of:




var rec = new GlideRecord('sys_template');


rec.initialize();


rec.table = 'incident';


rec.name = current.variable_pool.inc_temp_name;


rec.short_description = current.variable_pool.inc_temp_short_desc;


// --- Template --//



rec.template = "category=" + current.variable_pool.inc_temp_category + "^subcategory=" + current.variable_pool.inc_temp_subcategory; //im adding this part



rec.insert();



This is just an example and it requires the variables on your catalog item to be references to the actual sys_choice records of the incident category and subcategory fields. If you want to hardcode the sys_id in there,you could go with something like:


rec.template = "category=sys_id^subcategory=sys_id";


View solution in original post

9 REPLIES 9

Hi Jocelyn,


The template section is, as mentionned by Akhil, only a field on the template table: sys_template.template.


It stores its information under the structure of an encoded query.


Cheers,


Phil


Thanks Philippe for clarifying!



My question now is, how can I get the display value of each current.variable_pool?


If what you want to do is put the value entered in variables inside of the template field, you would need to go with something along the lines of:




var rec = new GlideRecord('sys_template');


rec.initialize();


rec.table = 'incident';


rec.name = current.variable_pool.inc_temp_name;


rec.short_description = current.variable_pool.inc_temp_short_desc;


// --- Template --//



rec.template = "category=" + current.variable_pool.inc_temp_category + "^subcategory=" + current.variable_pool.inc_temp_subcategory; //im adding this part



rec.insert();



This is just an example and it requires the variables on your catalog item to be references to the actual sys_choice records of the incident category and subcategory fields. If you want to hardcode the sys_id in there,you could go with something like:


rec.template = "category=sys_id^subcategory=sys_id";


Thanks so much Philippe. I appreciate your time.



Thanks to Akhil as well!


leyakath shaik
Tera Contributor

I have similar requirement but need to perform the same using flow designer? When i select Template feild and I am not getting toggle option to write script?, Any idea how can we achieve this?