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 😄

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@StewartFletcher 

you are writing this in inbound action?

did you add gs.info() and log the email body?

share screenshots

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

StewartFletcher_0-1758797849235.png

 

@StewartFletcher 

oh you are using flow, then it won't work there directly.

the way to access body in flow is this

Easiest way to Trigger Catalog Item Request via Inbound Email 

also check this

How to read body text in Inbound EMAIL Flow 

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

Hi @StewartFletcher ,

 

This is not an inbound action script, so cannot access email object directly.

Use the below code to access email_body.

var body = fd_data.trigger.body_text;

 

Also, remember to return your value.

 

Thanks

Anand