The CreatorCon Call for Content is officially open! Get started here.

Parsing a subject from incoming email into different variables

TylerJ333505898
Tera Contributor

Good Morning, 

 

Can anyone help or point me to a tool OOTB that i can use to separate this subject line into multiple variables on a catalog item? 
Subject Line =    Termination for John Smith, 603677 (2025-01-10)

 

Trying to separate the name into one variable the number into another along with the date into a third. the body of the email is useless to use as everything is in the subject. 

1 ACCEPTED SOLUTION

JenniferRah
Mega Sage
Mega Sage

I'm guessing you are using an inbound action for this? You will have to script it. If it's always in this format, you can do something like this: 

var subject = email.subject;
var arr = [];
subject = subject.substring(16); //Removes the "Termination for " beginning string
var commalocation = subject.indexOf(',');
var name = subject.substring(0, commalocation); //The name is the resulting string up to the comma
subject = subject.substring(commalocation + 1).trim();
arr = subject.split(' ');
var id = arr[0]; //The first part of the resulting string is the ID
var date = arr[1].substring(1, arr[1].length - 1); //The second part of the resulting string is the date in parentheses

View solution in original post

6 REPLIES 6

@TylerJ333505898 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@TylerJ333505898 

As per new community feature you can mark multiple response as correct

If my response helped please mark it correct as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader