- 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-02-2019 07:00 AM
Try like this and if it does not work, let me know till where does yoru log statement returned. I changed addInfo to logs. Kindly check in system logs.
var template_id = '4e0f98cddbbbab0022f5d404ca9619e9';
var systemp = new GlideRecord('sys_template');
systemp.addQuery('sys_id',template_id);
systemp.query();
gs.log("number of templates:"+systemp.getRowCount());
if(systemp.next()){
var IncRec = new GlideRecord('incident');
IncRec.addQuery('u_template',template_id );
IncRec.query();
gs.log("temp sys_id is:"+IncRec);
gs.log("number of templates:"+IncRec.getRowCount());
if(IncRec.next()){
IncRec.state = systemp.state;
gs.log("checking template state:"+IncRec.state);
IncRec.short_description = systemp.short_description;
gs.log("checking template short description:"+IncRec.short_description);
var id = IncRec.insert();
}
}
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-03-2019 07:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 07:52 AM
So what is the output of this line
gs.log("number of templates:"+systemp.getRowCount());
If its 1 or more, then you shodul get these 2 logs as well. kindly check
gs.log("temp sys_id is:"+IncRec);
gs.log("number of templates:"+IncRec.getRowCount());
If you get 0, then it means the template_id could be wrong. check that once.
4e0f98cddbbbab0022f5d404ca9619e9
Also, why are you using this line IncRec.addQuery?
IncRec.addQuery('u_template',template_id );
IncRec.query();
gs.log("temp sys_id is:"+IncRec);
gs.log("number of templates:"+IncRec.getRowCount());
if(IncRec.next()){
If it does not exist, then don't you want to create a incident record with the values?
Kindly provide responses to each of the points to assist you further.
Mark the comment as helpful if it is helping to debug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2019 12:18 AM
HI asif,
gs.log("number of templates:"+systemp.getRowCount());
The number of rows is comming "1" not 0.
For 2nd point why i am addquery means i need to set values to incodent from that sys_template.? Am i doing correct? or any other suggestion?
IncRec.addQuery('u_template',template_id );
IncRec.query();
gs.log("temp sys_id is:"+IncRec);
gs.log("number of templates:"+IncRec.getRowCount());
if(IncRec.next()){