The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Community Alums
Not applicable

Hello Community,

 

My customer used SharePoint Lists to manage incidents previously and is now migrating to ServiceNow Incident Management. Previously, end users sent emails with a specific subject to SharePoint. However, they will now send emails to ServiceNow. The customer's requirement was to generate incidents whenever emails with a specific subject were received. To fulfill this, I created an Inbound Action.

 

This article explains how to use ServiceNow Inbound Actions to automatically create incidents from emails based on specific criteria. It includes a detailed example using an email with the subject "ISG/Support" to populate incident fields with extracted information.

 

1. What is an Inbound Action?

An inbound action in ServiceNow is a mechanism that triggers automated processes based on predefined conditions associated with incoming emails. It acts as a powerful tool for processing incoming communication, allowing for the automatic creation or updating of records within the platform, such as incidents, tasks, or any other relevant entity.

 

2. How Does an Inbound Action Work?

When an email is received by the ServiceNow platform, the inbound action is initiated by evaluating certain criteria, such as the email subject, sender's details, or specific keywords within the email body. Once the predefined conditions are met, the action executes a set of scripts or processes defined by the user to perform various tasks, such as creating an incident, updating records, or sending notifications.

 

EZServiceNow_1-1702903411107.png

 

3. Example: Creating an Incident with Inbound Action

Let's consider an example where an inbound action is set up to automatically generate an incident in ServiceNow when an email subject line starts with "ISG/Support." Here's a breakdown of the script used in this scenario and the data mapping details:

EZServiceNow_2-1702904397867.png

Steps to Create Inbound Action:

Follow these steps:

  • Navigate to System Policy > Inbound Action.
  • Click New to create a new inbound action.
  • Enter a name and other details for the inbound action.

EZServiceNow_3-1702904795222.png

Script:

 

current.short_description = email.subject.toString();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text.toString();

var emailBody = email.body_text.toString();

//Get Reference ID of SharePoint
var inputString = email.subject;
var referenceIDIndex = inputString.indexOf(":") + 2;
var referenceID = inputString.substring(referenceIDIndex, inputString.indexOf(" ", referenceIDIndex)).trim();

current.u_sharepoint_reference_id = referenceID;


// Extracting projectNumber
var projectNumberIndex = emailBody.indexOf("*Project#:*") + 12;
var projectNumber = emailBody.substring(projectNumberIndex, emailBody.indexOf("-", projectNumberIndex)).trim();

// Extracting projectName
var projectNumberIndex2 = emailBody.indexOf(" - ") + 3;
var projectNumber2 = emailBody.substring(projectNumberIndex2, emailBody.indexOf(":", projectNumberIndex2)).trim();

//gs.info('Create Incident: SharePoint -- ' + projectNumber);

if (projectNumber) {
    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();
        current.u_project = projectSysID;
    }
}

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

if (date != '' && time != '') {

    var combinedDateTime = new GlideDateTime();
    combinedDateTime.setDisplayValue(date + " " + time);
    current.opened_at = combinedDateTime;
}

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

//gs.info('Create Incident: SharePoint -- ' + emailOfPersonRequiringSupport);

if (emailOfPersonRequiringSupport != '') {
    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
        current.caller_id = personRequiringSupportSysId;
        //gs.info("Create Incident: SharePoint Incident: The sys_id for Person Requiring Support is: " + personRequiringSupportSysId);
    }
}

// Extracting submittedBy
var submittedByIndex = emailBody.indexOf("*Submitted by: *") + 18;
var submittedBy = emailBody.substring(submittedByIndex, emailBody.indexOf("*Person Requiring Support:*", submittedByIndex)).trim().toString();

var sumittedBySysId;
if (submittedBy != '') {
    var userRecord = new GlideRecord('sys_user');

    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
        current.opened_by = sumittedBySysId;
        //gs.info("Create Incident: SharePoint: The sys_id for Submitted by is: " + sumittedBySysId);
    }
}



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(">", supportTicketLinkIndex)).trim();
var desc = '*Issue or Request: ' + issueOrRequest + '\n\n*******************\n\n*Description: ' + description + '\n\n*******************\n\n*Support Ticket Link: ' + supportTicketLink+'>';
current.description = desc;

//gs.info("Create Incident: SharePoint Incident:" + desc);

gs.info("Create Incident: SharePoint Incident:\n\n Subject : "+email.subject+"\n Submitted By : " + sumittedBySysId + "\n\n Reference ID: " + referenceID + "\n\n Person Requiring Support : " + personRequiringSupportSysId + "\n\n Data/Time : " + combinedDateTime + "\n\n Project: " + projectSysID + "\n\n Descritpion: " + desc + "\n\n*******************************************************************************************");

current.insert();

 

 

This script, triggered by the inbound action, extracts relevant information from the email body, and subject to populate fields in the incident record. Adjustments can be made to suit specific business needs, including additional fields or data processing logic.

 

By leveraging ServiceNow Inbound Actions, you can automate various tasks based on incoming emails, streamlining your incident management process and improving overall efficiency.

 

Remember to carefully test and adjust your Inbound Action script to ensure accurate and reliable automation for your specific use case.

 

Please mark it as helpful and accept it as a solution if it helps you in any way.

Regards,
Prasad - "Here to help and empower."

LinkedIn: https://www.linkedin.com/in/prasad-shelar-713b18185/

Comments
Osaretin Olumek
Tera Contributor

Hello Tera Guru, thanks for this elaborate and accurate guide to setting up an inbound email action. However, I have a question I was hoping you could help me with. I have an email inbound action configured to ingest contents of an email including a choice list, then creates a CSM Case. I recently was tasked with editing the choice list, removed some choices from the list. However, during testing, I am finding out that the removed choices are still been created after an email is ingested despite those choices been removed from the choice list. Is there any way to stop this from happening?

karan15
Tera Contributor

can we do this without using the script ?

Version history
Last update:
‎12-18-2023 05:26 AM
Updated by:
Community Alums
Contributors