fetching data from email body in server side script

Deepika54
Tera Contributor

Deepika54_0-1675164477691.png

Hello experts, I have a following email body. I want to fetch the 'Critical' value and store it in some variable in inbound action script . I also have the regex expression    Alert Level: (.*).

Can any1 tell me how to retrieve the value 'critical' and store it in a variable.

2 ACCEPTED SOLUTIONS

Pavankumar_1
Mega Patron

Hi @Deepika54 ,

you can get value like this

 

 

var alert=email.body.alert_level; //you can get value of alert value like this 

 

 

or try below it gives the Critical value

 

var bodyis=email.body_text; //gives you complete body of email
var alerttext=bodyis.split('Alert Level:')[1]; //This gives you text after Alert Level
var gettext=alerttext.split('HostName:')[0];//this gives the text before HostName

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

Hi @Deepika54 ,

yes that will work.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

12 REPLIES 12

Hi @Deepika54 ,

If it is resolved that is good. Glad to help you.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

use below script:

 

var alerttext=bodyis.split('Alert Level:')[1];

var alerttext2=alerttext.split('\n')[0];

//Or if above statement is not worked then use below code
var alerttext2=alerttext.split('<')[0];
Please mark the answer correct/helpful based on Impact.
Regards, Shekhar

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @Deepika54 ,

Please try this below code

var descr= email.body.description; // because i see this Critical value is in description field

var critical_Value= descr.split(' use from where you want to extract the text")  or you can use .slice()

 

Try the above lines of code.

 

Thank you,

Omkar

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.