- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2017 12:09 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:07 AM
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 07:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 09:56 AM
Thanks Philippe for clarifying!
My question now is, how can I get the display value of each current.variable_pool?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:07 AM
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:58 AM
Thanks so much Philippe. I appreciate your time.
Thanks to Akhil as well!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 04:28 AM
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?