- 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-24-2017 01:02 PM
Hi Jocelyn,
The template field on the sys_template stores the information under the following format:
company=sysID^cmdb_ci=sysID^assignment_group=sysID^EQ
So if you are to dynamically generate a template based on the variables of the requested item, you would need to generate a String that follows this structure.
If you want more examples, you can go to a template record and simple use the "Show XML" action to view how the value is stored.
Phil,
Cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2017 02:56 PM
Can you check what is the value of the below
current.variable_pool.inc_temp_name in log ? Try using current.variables.variable_name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2017 05:08 AM
Try using encoded query like below to populate data :
//Template
rec.template = "active=true^description=test^short_description=best thing"; //Don't use ^EQ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 03:36 AM
Hi Akhil,
The value of "current.variable_pool.inc_temp_name " is the name of the template provided in the service request form.
Right now, only 2 fields are being populated: Name and Short Description.
Not sure how to call the Template section.
Thanks!