Finding text in emails - inbound email actions

brycefraser
Giga Contributor

I am trying to create an inbound email action that takes our Separation Notification emails, finds the user name within the email, and then uses that to automatically disable the AD account associated.

The emails look something like this:

Good morning all,

Please be advised that the following employee has finished at St Andrews War Memorial Hospital.

Name:

John Smith

Employee No:

000000

Position:

Employee

The problem I am having is trying to pull the name from the email, currently I am trying to do so using email.body_text.indexof, e.g.;

var pos1 = email.body.indexof("Name:");

var pos2 = email.body.indexof("Employee No:");

var name = email.body.substring((pos1 + 1), (pos2 - 14));

Ideally this should set the variable "name" to whatever is between the Name: line and the "Employee No:" line.

When the code runs, however, all that returns for pos1, pos2 and name is "undefined". I can't seem to work out what is wrong.

Any help with this would be great.

Thanks!

1 ACCEPTED SOLUTION

ganeshb_
Tera Expert

Hi Bryce,


I don't think you need to do all this substring stuff. You can directly access/pull the elements of the email body as:


var xyz = email.body.name; OR var xyz = email.body.employee_no;


For email like :


Name:John Smith


                            Employee No:000000


                            Position:Employee




Please try , and let me know.



Thanks,


Ganesh


View solution in original post

5 REPLIES 5

Hi Ganesh



Thanks for the tip, i've given this a try and it does work when the name is on the same line as the label, e.g. Name: John Smith



I'll have to contact our HR team to see if they're able to change the email slightly.



Thanks again