Insights ServiceNow: Dynamic Inbound Action Email Parsing

ServiceNow: Dynamic Inbound Action Email Parsing

Challenges with Existing Platform Capabilities

If you have worked with ServiceNow before, then chances are you are familiar with the out-of-box system property that can discard any text below a specific message in a reply body (glide.pop3.reply_separators). This typically is the ideal solution for organizations that are smaller in size and have a repeatable process in place that can support this functionality. This feature is commonly recommended by ServiceNow given its simplicity and how it ties into the native platform capabilities.

What happens when your organization continues to mature by organizational function that suddenly has various requirements for email parsing? The reply separator system property will work for a single repeatable value, but now the requirement changed, and you now must watch for multiple values. This poses a challenge for companies that have various existing systems each configured differently when they ultimately should leverage a common service to use a standard email signature.

Concurrency always recommends leveraging out-of-box ServiceNow technologies whenever possible. This typically allows for smoother upgrades, easier management overall, and peace of mind. But for situations like the above where there are different data patterns, we ensure our custom solutions scale and are dynamic enough to adapt if the underlying organizational structure changes. After reading this blog, you will have discovered a solution that is constantly watching for specific phrases and parsed out of the email body before the data is updated onto the ticket.

NOTE: This solution can also be adapted to other inbound actions targeting other tables.

The Solution

One of our customers operating within the legal sector of the market required an automation that would parse out legal footer messages that they did not want brought to the ticket activity. In fact, some of the back-and-forth email communication would last long enough where truncation would occur due to marketing links and other erroneous text. To combat this, we implemented a solution that acts as a “chain of events” looking for specific messages of text to remove from the email reply.

The solution involves the following:

  1. Inbound action updated with custom code to retrieve the master system property and loop through child system properties.
    1. We leveraged the “Update Incident (BP)” inbound action as part of this, given that the requirement pertained to the incident module.
  2. master system property containing a comma-separated list of “child” system properties containing the phrases to parse out of email replies.
  3. A collection of child system properties containing the phrases to look for.
  4. A custom logging wrapper function to ensure it is parsing the appropriate data.

Inbound Action Code

NOTE: the request for this solution applied to the “Update Incident (BP)” inbound action and may need to be adapted to a different inbound action based on your ServiceNow organizational processes.

/*

Dynamic Inbound Action Email Parsing

Authors: Bryan Schrippe, Michael Dugan

Company: Concurrency, Inc.

*/

// logging flag, custom source definition, and log wrapper function

var loggingOn = gs.getProperty(‘glide.email.xyz.signatureLogging’);

var customSource = ‘xyz Signature Removal’;

function quickLogger(message) {

if (loggingOn == ‘true’) {

gs.log(message, customSource);

}

}

// get master property containing names of other properties to check

var signaturePropsToGet = gs.getProperty(‘glide.email.xyz.signaturelist’).split(‘,’);

quickLogger(‘Master list of properties: ‘ + signaturePropsToGet);

// get each signature and check email body for those values

for (var sig = 0; sig < signaturePropsToGet.length; sig++) {

// get signature

var signature = new GlideRecord(‘sys_properties’);

signature.addQuery(‘name’, signaturePropsToGet[sig]);

signature.query();

if (signature.next())

{ quickLogger(‘Found signature property: ‘ + signature.name);

// capture value from system property

var valueToCheck = signature.value;

// check body text for signature value

if (email.body_text.toString().indexOf(valueToCheck) != -1) {

quickLogger(sys_email.uid + ‘: Signature value found in email body: ‘ + valueToCheck); //

remove signature(s)

email.body_text = email.body_text.replace(valueToCheck, ”).trim();

} else {

// allow email to process normally

quickLogger(sys_email.uid + ‘: Signature value not found in email body: ‘ + valueToCheck);

}

}

}

email.body_text.trim();

Master System Property

First, create a new system property and replace “xyz” with your customer naming convention. This system property will track which phrases to parse out of the email replies:

Name: glide.email.xyz.signatureList

Description: Master property for removal of email signature processing. Contains a list of system properties that tell the automation which values to look for, and to remove if found.

Type: string

Value: glide.email.xyz.test1,glide.email.xyz.test2,glide.email.xyz.test3

System Properties Containing Phrases for Removal

Create additional “child” system properties that match the design above, but the ending should be different. See below for an example.

Every time you create a new “child” system property containing a phrase that you would like parsed out of an email reply, add it to the Master System Property so it can be detected and removed as part of the processing.

Name: glide.email.xyz.test1

Type: string

Value: Please consider the environment first before printing this email.

Demo

Say for this example we want to parse out roles/titles of employees within the company (for whatever reason). Make sure your child properties have the values you want to parse out (e.g.: SYSTEMS ENGINEER, TECHNICAL ARCHITECT, etc.). Now that I have made that change within my demo ServiceNow instance, I am ready to send an email and see if it works. Here is my email:

This email will be targeting INC0000001 for an update, given that the number of the task is within the subject which is an identifier within ServiceNow’s engine processing. Once I click send, it should simply add an additional comment on the incident with my email signature. My role should not make it onto the comment. Here’s a before and after look at the incident:

BEFORE:

AFTER:

Notice the “SYSTEMS ENGINEER” text is missing? As you can see, the title from my email signature was successfully removed from the email reply to the incident. This is a great example of how specific phrases can be added so they are parsed out of future email replies within your organization.

Conclusion

After you have updated the appropriate inbound action with the custom code located above, created a system property that will act as the “master” list, created subsequent system properties as “children” for this process, and updated the master system property with the names of the child system properties, the inbound action is set up in a way where it will loop through the contents of the email reply and parse out your organizational messages needing to be removed!

Thanks for reading!!

Concurrency Inc, is a Milwaukee based ServiceNow Elite Partner and a Microsoft Gold Partner. We are a consultation company that takes pride in our organizational change management approach which yields high customer success in seizing an organization’s desired business outcomes. If you have any consultation requests, or would just like to chat – please feel free to reach out to sales@concurrency.com.