How to pull a reference number from an email body text for inbound email in flow designer

H_22
Tera Contributor

Hi



I am trying to use inbound email in flow designer to update an existing RITM ref number.

The ref number is in the email body and will show like this on the inbound email

Version Visit Email Address:  RITM1234567@new,employee.com

The ref number will be different each time but the @new.employee.com will be the same 
I need a script to split the ref number on the email body and check if that ref number exists and if so then to update the ref with the email.



Thanks 

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

I guess you will have to script a bit to get the needed data.

Basically, store the emailtext in a variable, split the data into an array using newline as a separator.

Loop through the array (each line of text in the mail).

If the identifier is found, extract the RITM number.

Return the RITM number to the Flow.

H_22
Tera Contributor

Hi

 

I am not good with scripting, do you have anything i could try please?

 

Thanks 

I've made a simple example script for you to start with.

And attached a simple flow image that shows how it can be used.

 

var emailText = fd_data.trigger.inbound_email.body.toString(); // store the entire email body into a variable
var ritmNumber = '';
var identifier = '@new,employee.com.'; // your identifier to find the correct line in the text, change if needed

var arrayText = emailText.split('\n'); // split the email text into an array using newline as separator
for (var i=0; i<arrayText .length; i++){
    if (arrayText [i].indexOf(identifier) != -1){ // if we found your identifier
        ritmNumber = arrayText[i];
        ritmNumber = ritmNumber.replace(identifier, '');  // remove the identifier text from the string
        ritmNumber = ritmNumber.replace('Version Visit Email Address:', ''); // remove the starting text in the string
        ritmNumber = ritmNumber.trim(); // remove remaining whitespaces
        break;
    }
}
return ritmNumber;

 

Flow overview:

flow-extract-ritm-numer-from-email.png

Flow step 1 in detail:

flow-extract-ritm-numer-from-email-step1-detail.png