Pull information from email body for inbound action?

na93
Mega Expert

Hi,

I have an inbound action which I have configured, but there is one part that I cannot do and was wondering if it was possible to do or if anyone could help?

We basically get an email where in the email body it has "The following user: Jane Doe is.."

I basically want to be able to pull whatever is between user: and is into a variable to get the persons name, is this possible?

Cheers,
Nabeel

1 ACCEPTED SOLUTION

Abhishek77
ServiceNow Employee
ServiceNow Employee

I would use a regular expression for this just to make. Your code will look like this

var match= /.*:(.*)\sis/g.exec(str)[1].trim(); //str is the variable that is decalred to store the string

View solution in original post

5 REPLIES 5

Mike Patel
Tera Sage

try something like

var user = email.body.user.split(":").toString();

var name = user[0].split("is").toString();

var final = name[0];

sachin_namjoshi
Kilo Patron
Kilo Patron

Yes, this is possible.

you will to use javascript string methods to extract information from email body in variable.

https://www.w3schools.com/js/js_string_methods.asp

Please follow below sample code to find index of your keywords and use another string function to store value in variable

str1 = email.body_text.indexOf("%user:");

str2 = email.body_text.indexOf("is"); 

 

Regards,

Sachin

Abhishek77
ServiceNow Employee
ServiceNow Employee

I would use a regular expression for this just to make. Your code will look like this

var match= /.*:(.*)\sis/g.exec(str)[1].trim(); //str is the variable that is decalred to store the string

Worked perfectly, thank you so much!!