- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 09:10 PM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 12:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 09:59 PM
What happens when the email has the name on the same line, like:
Name: John Smith
I think the carriage return is messing it up. The carriage return symbol is \n
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2015 07:16 PM
Hi Mike
Thanks for your response, i'll give that a try.
Even if it does work, unfortunately I'll be unable to change the email that is sent as it's generated automatically from our payroll system.
I'll report back with how it went.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2015 09:55 PM
Try to use toString() before substring()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 12:45 AM
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