cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
MyNameIsAjax
Level: Powered On

Extracting Strings from Email Body

Sorry if this has already been posted...

This is my conundrum.

We get emails to managers with the particulars of an event (PTO/Vacation/Sick) and I am looking for a way to extract the information in Flow.

 

This is the body of the Email message in flow.  I can isolate parts of it, but unsure about others.

 

Time Off Request(s) Approved by sysadmin  <-- This is the key that I have if an email comes in with this in the Body

Employee: John Smith  <-- I need a script that will isolate name, given that name will be various lengths.
Hours: 8.00
Time-Off Type: Paid Time Off
Dates:
09-24-2018 at 08:00:00

 

Everything else I can Pretty much do but its the Employee name that is holding me up.  

I can find 'Employee: ' in the message body but I can not find a way to account for something that goes until end of line.  I can not isolate the name through the AAD as its going to the manager, not to the employee themselves.

 

I know someone has done this before as I cant be the only one.  


Many thanks in advance.

 

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Extracting Strings from Email Body

Hi @MyNameIsAjax,

 

Could you share a screenshot of your current Flow configuration?

What you mean is that you want to get the name of the Employee in the body of the email, here is the String after "Employee:".

Have you tried using Html to text to convert the body of a message into text?

Could you provide the format of your email body?

I wonder if the format is similar to the following, maybe you could refer to the link below, use the function provided by Expression to extract the string you want from email body text.

29.PNG

https://powerusers.microsoft.com/t5/Building-Flows/Read-email-content-from-body-of-the-email-extract...

https://powerusers.microsoft.com/t5/General-Flow-Discussion/Using-a-flow-to-extract-email-body-detai...

 

Please take a try.

 

Best Regards,

Barry

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MyNameIsAjax
Level: Powered On

Re: Extracting Strings from Email Body

This is what I have done so far and made some good progress on it.

1.  Convert to Text based on the condition flow

2. Get the EmployeeName start Index

Add(int(indexOf(triggerBody()?['Body'],'Employee')),10)

3. Get the EmployeeName end index based upon the next line in the email which should be 'hours:'.  When it finds that string that is the end of the employee name

sub(Sub(int(indexOf(triggerBody()?['Body'],'Hours')),6),Outputs('EmpIndexStartY'))

4.  Now I get the employeename based upon the start and end indexes above

Substring(triggerBody()?['Body'],Outputs('EmpIndexStartY'),Outputs('EmpIndexEndY'))
5.  I am repeating this process for Hours and the number of hours the person has but it brings up an issue.  The issue being that the hours are presented in this format 8.00 but if its 16.00 then there is an extra character there.  Not sure if there is a way to look for a character inside when I am isolating the hours and if its 4 in length or 5 in length but all numeric and then eliminate non-numerics.  Or grab the first 2 characters and if the second is a '.' then just use the first character.
6.  The next issue that I am going to run into (not there yet), is the date(s) line.  If their time off spans more than one day then multiple dates are presented on the email on different lines.  I need to loop through the lines (somehow determining if there is but a single date or multiple dates on multiple lines).  This could get messy.
 
tl;dr - 5 and 6 
 
here is a screenshot of my flow so far.
 
Flow.PNG
 
 
 

 

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 267 members 4,458 guests
Recent signins:
Please welcome our newest community members: