The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Pulling email body text into fields on a form

StewartFletcher
Tera Expert

I've been doing some digging and trying to find an answer to this - I've found various different questions/articles that are marked as correct and working. However, they do not work for me as I get an error when trying to create the record stating 'Error: "email" is not defind.,Detail: "email" is not defined.

 

Here are the two methods I've found that are 'correct' but fail -:

var splitext=email.body_text;

var splittoget=splitext.split('My_Department_Number:')[1];

var splittogetfinal=splittoget.split(' ')[0]; //This will give final result

 

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

 

Neither work and throw the same error. Is something else required before this script to define email?

 

For reference, this is intended to be an Inbound Email trigger on a flow, which creates a record and will populate various fields based on what is put on the email. There will be multiple fields to populate, and we want to split each field out from the email, which I assume using the above options for script would work.

 

Obviously, I'm changing the details in the above to be the field on the email in question, before anybody asks if I changed them 😄

1 ACCEPTED SOLUTION
10 REPLIES 10

This shouldn't be required to get this to work surely.

@Bhuvan  tried it anyway, made no difference.

tejas1111
Tera Contributor

hi if you have to access the unbound email body values

Synatax: 

var short_desc=fd_data.trigger.inbound_email.body_text;
//gs.info("test55 my email body text +"+short_desc);
return short_desc;

 

steps:

1) i have created flow .trigger inbound email 

(and create the incident with email body);

tejas1111_0-1758804793834.png

2)its working .Please find screenshot

after tessting

tejas1111_1-1758804923753.png

Created incident

tejas1111_2-1758804991816.png

Actual email

tejas1111_3-1758805088491.png

 

 

If my response/article helped you, please mark it as the correct answer and close the thread — this helps other readers in the community.

Regards,

Tejas 
🚀 ServiceNow Developer | 🏆 HackaNow Finalist | 💡 Community Contributor
📧 Email: tejas.adhalrao11@gmail.com
🔗 LinkedIn: linkedin.com/in/tejas1018

 

Doesnt' work as needed as it pulls the whole body of the email. I've figured it out now anyway.