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

tejas1111
Tera Contributor

Hi @StewartFletcher ,

Why you see the error

  • In Business Rules or Script Actions for inbound email, you can access the email object via email or email.body_text.

  • In Flow Designer Inbound Email triggers, there is no email object — instead, Flow Designer passes email content through Data Pills (like Body Text, Subject, From, etc.).

What you should do

  1. Don’t use email.body_text in Flow Designer.

    • Use the Data Pill → Email → Body Text directly.

    • If you want to split text, use a Script Step in the flow.

// input: bodyText = trigger.current.body_text (map the data pill here)
var result = {};
var splitext = bodyText.split('My_Department_Number:')[1];
if (splitext) {
    result.departmentNumber = splitext.split(' ')[0];
}
var alertText = bodyText.split('Alert Level:')[1];
if (alertText) {
    result.alertLevel = alertText.split('HostName:')[0];
}
return result;

 

 

  • Then map result.departmentNumber and result.alertLevel to the fields you want on your record.