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

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

Does this work in the flow designer or do i have to use the inbound action area. it does always come in this format was trying to use flow but no luck. 

You can probably still do it with Flow, but you would need to change it to use the Flow inputs rather than the email.subject line like in my script.

Ankur Bawiskar
Tera Patron
Tera Patron

@TylerJ333505898 

you will have to perform string manipulation from that and extract values

Also if the pattern change in future then script needs to be updated as well

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