- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 01:45 AM
Hi All,
I have several email inbound actions like the one below to create incidents and apply templates -
generateIncidents();
function generateIncidents(){
var parentIncident = createParentIncident();
createChildIncident(parentIncident);
}
function createParentIncident(){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.applyTemplate("Leaver Request"); //Apply the Template of the Parent Incident
grIncident.insert();
return grIncident.getUniqueValue();
}
function createChildIncident(parentIncident){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.applyTemplate("Leaver Request - IT"); //Apply the Template of the Child Incident
grIncident.setValue("parent_incident", parentIncident);
grIncident.insert();
}
This is working when certain emails come through.
What I would also like is for the Incident to have the Short Description from Email Subject and Description from Email body, I understand this code is -
current.short_description = email.subject;
current.description = setDescription(email.body_text);
I am struggling to understand where to place this code or if this is even correct to achieve this?
Any help would be much appreciated.
Thanks,
Alex
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 01:49 AM
i am assuming here you want to set it on parent as well as child incident record , if yes try now
generateIncidents();
function generateIncidents(){
var parentIncident = createParentIncident();
createChildIncident(parentIncident);
}
function createParentIncident(){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.short_description = email.subject;
grIncident.description = email.body_text;
grIncident.applyTemplate("Leaver Request"); //Apply the Template of the Parent Incident
grIncident.insert();
return grIncident.getUniqueValue();
}
function createChildIncident(parentIncident){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.short_description = email.subject;
grIncident.description = email.body_text;
grIncident.applyTemplate("Leaver Request - IT"); //Apply the Template of the Child Incident
grIncident.setValue("parent_incident", parentIncident);
grIncident.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 01:49 AM
i am assuming here you want to set it on parent as well as child incident record , if yes try now
generateIncidents();
function generateIncidents(){
var parentIncident = createParentIncident();
createChildIncident(parentIncident);
}
function createParentIncident(){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.short_description = email.subject;
grIncident.description = email.body_text;
grIncident.applyTemplate("Leaver Request"); //Apply the Template of the Parent Incident
grIncident.insert();
return grIncident.getUniqueValue();
}
function createChildIncident(parentIncident){
var grIncident = new GlideRecord("incident");
grIncident.initialize();
grIncident.short_description = email.subject;
grIncident.description = email.body_text;
grIncident.applyTemplate("Leaver Request - IT"); //Apply the Template of the Child Incident
grIncident.setValue("parent_incident", parentIncident);
grIncident.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 02:17 AM
Thank you, this worked!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 01:53 AM
Hi,
Change cuurent to object name like
grIncident.short_description = email.subject;
grIncident.description = setDescription(email.body_text);
add it into the functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 02:13 AM
Hi Alex,
You can achieve this in two ways
1. You can directly configure it in your inbound email action without any code as shown in below screenshot:
2. You can add that in your functions inside the script as Harshvardhan has suggested.
Please mark the answer correct and helpful if it resolved your purpose or helped you at all.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)