- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2019 06:55 AM
HI all,
I have a requirement that "sys_template" fields values needs to populate on "incident" inbound email action
Please find the below script for that but it is not working..This script i have written in my inbound action (this inbound placed in incident table)
u_template is a reference field in incident table
var template_id = '4e0f98cddbbbab0022f5d404ca9619e9';
var systemp = new GlideRecord('sys_template');
systemp.addQuery('sys_id',template_id);
systemp.query();
gs.addInfoMessage("number of templates:"+systemp.getRowCount());
if(systemp.next()){
var IncRec = new GlideRecord('incident');
IncRec.addQuery('u_template.sys_id',template_id );
IncRec.query();
gs.addInfoMessage("temp sys_id is:"+IncRec);
gs.addInfoMessage("number of templates:"+IncRec.getRowCount());
if(IncRec.next()){
IncRec.state = systemp.state;
gs.addInfoMessage("checking template state:"+IncRec.state);
IncRec.short_description = systemp.short_description;
gs.addInfoMessage("checking template short description:"+IncRec.short_description);
var id = IncRec.insert();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:38 AM
Hi Srisk,
Actually, you can use a OOB Function ApplyTemplate to apply it to your incident. Here is how you can do this.
var template_name = 'Your Template Name'; // in place of sys_id mention your template name.
var IncRec = new GlideRecord('incident');
IncRec.applyTemplate(template_name);
IncRec.update();
Mark the comment as a correct answer and also helpful once worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 03:32 AM
can you share the entire code, where you are running this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:04 AM
Asif i have tried in back gorund script
var gr = new GlideRecord('sys_template');
if (gr.get('c20f98cddbbbab0022f5d404ca9619e2')) {
gs.print(gr.name);
gs.print(gr.table);
gs.print(gr.active);
var templatee = gr.template.toString();
gs.print(gr.templatee.short_description);
}
evrthing is comming if i put gs.print(gr.template); i mean combining all field values
but when i put gr.template.short_description; it is comming undefined
Because "template" is not a reference field on "sys_template" table any idea how to get individual values

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:23 AM
Hi,
You can directly use gr.short_description as it exists in sys_template table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:30 AM
Here short_description,description,impact these all fields are not in "sys_template" table these are present in "incident" table.
Actually in sys_template table we have a field called "template" this template dependent field mapped to "incident" table
and that template field is not a reference field it is a type called "Template value"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:38 AM
Hi Srisk,
Actually, you can use a OOB Function ApplyTemplate to apply it to your incident. Here is how you can do this.
var template_name = 'Your Template Name'; // in place of sys_id mention your template name.
var IncRec = new GlideRecord('incident');
IncRec.applyTemplate(template_name);
IncRec.update();
Mark the comment as a correct answer and also helpful once worked.