Include Email Subject/Body with Template from Inbound Email Action

Community Alums
Not applicable

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

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

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();
}

View solution in original post

4 REPLIES 4

Harsh Vardhan
Giga Patron

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();
}

Community Alums
Not applicable

Thank you, this worked!

Omkar Joshi
Giga Guru

Hi,

 

Change cuurent to object name like 

 

grIncident.short_description = email.subject;

grIncident.description = setDescription(email.body_text);

 

add it into the functions.

 

 

 

Mohit Kaushik
Mega Sage
Mega Sage

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:

find_real_file.png

 

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

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)