
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 02:10 AM
Hello Community!
Posting a question after a long time.
I'm working on a requirement: an Incident Should be created after a new email subject starting with 'ISG/Support' is received on the instance.
Preview of Received Email: (Pleas refer to the attached email body in text format.)
Field Mapping Details:
Fields in the Email | Incident Table Columns on ServiceNow | Comment |
Email Subject | Short Description | |
Submitted by | Opened by | |
Person Requiring Support | Caller | The caller is a reference field to the sys_user table. |
Glide sys_user table with email = 'Email of Person Requiring Support' and set the value on Caller. | ||
Email of Person Requiring Support | ||
Date + Time | Created | |
Project | Project | Project is referrence field to u_prwt_project. |
Glide the u_prwt_project table with u_code = code from the email body line e.g. *Project#:* 620 - Executive | ||
Then the code = 620 | ||
Issue or Request + Description + Support Ticket | Description | |
Work notes | Email body text |
|
I have configured Inbound Action with the following details:
Script:
gs.info("Create Incident: SharePoint Incident: Here");
if (current.getTableName() == "incident") {
var emailBody = email.body_text;
// Extracting submittedBy
var submittedByIndex = emailBody.indexOf("*Submitted by: *") + 16;
var submittedBy = emailBody.substring(submittedByIndex, emailBody.indexOf("*Person Requiring Support:*", submittedByIndex)).trim();
// Extracting personRequiringSupport
var personRequiringSupportIndex = emailBody.indexOf("*Person Requiring Support:*") + 26;
var personRequiringSupport = emailBody.substring(personRequiringSupportIndex, emailBody.indexOf("*Email of Person Requiring Support:*", personRequiringSupportIndex)).trim();
// Extracting emailOfPersonRequiringSupport
var emailOfPersonRequiringSupportIndex = emailBody.indexOf("*Email of Person Requiring Support:*") + 37;
var emailOfPersonRequiringSupport = emailBody.substring(emailOfPersonRequiringSupportIndex, emailBody.indexOf("*Phone Number:*", emailOfPersonRequiringSupportIndex)).trim();
// Extracting phoneNumber
var phoneNumberIndex = emailBody.indexOf("*Phone Number:*") + 16;
var phoneNumber = emailBody.substring(phoneNumberIndex, emailBody.indexOf("-----------------------------------------------------------------", phoneNumberIndex)).trim();
// Extracting date
var dateIndex = emailBody.indexOf("*Date:*") + 7;
var date = emailBody.substring(dateIndex, emailBody.indexOf("*Time:*", dateIndex)).trim();
// Extracting time
var timeIndex = emailBody.indexOf("*Time:*") + 7;
var time = emailBody.substring(timeIndex, emailBody.indexOf("*Project#:*", timeIndex)).trim();
// Extracting projectNumber
var projectNumberIndex = emailBody.indexOf("*Project#:*") + 12;
var projectNumber = emailBody.substring(projectNumberIndex, emailBody.indexOf("-", projectNumberIndex)).trim();
gs.log('--->' + projectNumber);
// Extracting projectName
var projectNumberIndex2 = emailBody.indexOf(" - ") + 3;
var projectNumber2 = emailBody.substring(projectNumberIndex2, emailBody.indexOf(":", projectNumberIndex2)).trim();
// Extracting issueOrRequest
var issueOrRequestIndex = emailBody.indexOf("*Issue or Request:*") + 20;
var issueOrRequest = emailBody.substring(issueOrRequestIndex, emailBody.indexOf("-------------------------------------------------------------------", issueOrRequestIndex)).trim();
// Extracting description
var descriptionIndex = emailBody.indexOf("*Description: *") + 15;
var description = emailBody.substring(descriptionIndex, emailBody.indexOf("*Support Ticket:*", descriptionIndex)).trim();
// Extracting supportTicketLink
var supportTicketLinkIndex = emailBody.indexOf("*Support Ticket:*") + 17;
var supportTicketLink = emailBody.substring(supportTicketLinkIndex, emailBody.indexOf("Reply", supportTicketLinkIndex)).trim();
var projectSysID;
// Get Project sys id
var projectGR = new GlideRecord('u_prwt_project');
projectGR.addQuery('u_number', projectNumber);
projectGR.query();
// Check if a record with the specified number exists
if (projectGR.next()) {
projectSysID = projectGR.getUniqueValue().toString();
}
/*
// Logging the extracted variables
gs.info("Submitted by: " + submittedBy);
gs.info("Person Requiring Support: " + personRequiringSupport);
gs.info("Email of Person Requiring Support: " + emailOfPersonRequiringSupport);
gs.info("Phone Number: " + phoneNumber);
gs.info("Date: " + date);
gs.info("Time: " + time);
gs.info("Project#: " + projectNumber);
gs.info("Issue or Request: " + issueOrRequest);
gs.info("Description: " + description);
gs.info("Support Ticket Link: " + supportTicketLink);
*/
var sumittedBySysId;
var userRecord = new GlideRecord('sys_user');
// Use an encoded query to find the user with the name 'Gwen Demby'
userRecord.addQuery('name', submittedBy);
userRecord.query();
// Check if a record was found
if (userRecord.next()) {
// Get the sys_id of the user
sumittedBySysId = userRecord.sys_id.toString(); // Converting to string if needed
gs.info("Create Incident: SharePoint Incident: The sys_id for Submitted by is: " + sumittedBySysId);
}
var personRequiringSupportSysId;
var userRecord2 = new GlideRecord('sys_user');
// Use an encoded query to find the user with the email
userRecord2.addQuery('email', emailOfPersonRequiringSupport);
userRecord2.query();
// Check if a record was found
if (userRecord2.next()) {
// Get the sys_id of the user
personRequiringSupportSysId = userRecord2.sys_id.toString(); // Converting to string if needed
gs.info("Create Incident: SharePoint Incident: The sys_id for Person Requiring Support is: " + personRequiringSupportSysId);
}
//Get Reference ID of SharePoint
var inputString = email.subject;
var referenceIDIndex = inputString.indexOf(":") + 2;
var referenceID = inputString.substring(referenceIDIndex, inputString.indexOf(" ", referenceIDIndex)).trim();
//current.opened_by = sumittedBySysId;
current.short_description = email.subject;
current.u_sharepoint_reference_id = referenceID;
//current.caller_id = personRequiringSupportSysId;
var combinedDateTime = new GlideDateTime();
combinedDateTime.setDisplayValue(date + " " + time);
current.opened_at = combinedDateTime;
current.u_project = projectSysID;
current.description = '*Issue or Request: ' + issueOrRequest + '\n\n*******************\n\n*Description: ' + description + '\n\n*******************\n\n*Support Ticket Link: ' + supportTicketLink;
current.work_notes = sumittedBySysId + "\n\n" + referenceIDreferenceID + "\n\n" + personRequiringSupportSysId + "\n\n" + combinedDateTime + "\n\n" + projectSysID + "\n\n" + description + "\n\n*******************************************************************************************\n\n\nIncident is created from Sharepoint:--> \n" + email.body_text + "\n\n Project ID: " + projectNumber;
current.insert();
gs.info("Create Incident: SharePoint Incident:" + sumittedBySysId + "\n\n" + referenceIDreferenceID + "\n\n" + personRequiringSupportSysId + "\n\n" + combinedDateTime + "\n\n" + projectSysID + "\n\n" + description + "\n\n*******************************************************************************************");
}
Please let me know the correct solution 🙂
Thanks in Advance!
-Prasad
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 05:28 AM - edited 12-18-2023 05:29 AM
I found the correct solution by making slight modifications to the script.
Find the correct solution here: A Guide to Inbound Actions: Automated Incident Creation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 03:33 AM
Hi @Community Alums
Where exactly are you stuck? What is not working? Have you checked the syslog table for any error messages?
And also, please take a look on the following page. It describes how you can let ServiceNow do the body parsing and extracting the variables. There is no need to implement this by yourself!
https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/notification/reference/r_SetFieldValsFromTheEmailBody.html
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 07:47 AM - edited 12-16-2023 08:08 AM
Hi@Maik Skoddow, Thanks for your response.
When I'm testing this Inbound Action it is not creating an Incident. This Inbound Action has low order; so no chance of conflicts. It shows this log message:
Referred provided doc, but no luck 😞
What I'm looking for?
I'm not sure why this is not working. I need your/community's help to resolve this issue or alternative solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 05:28 AM - edited 12-18-2023 05:29 AM
I found the correct solution by making slight modifications to the script.
Find the correct solution here: A Guide to Inbound Actions: Automated Incident Creation