cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
snydertl
Frequent Visitor

Taking multiple pieces of data from an email body to run conditions on

Hi all,

 

I've searched for a couple of days now but haven't found anything that matches what I am trying to do.  We have someone that gets a weekly email with a bunch of information about new hires.  This person wants to take the name of each new hire and send them a welcome email.  The issue arises when there are multiple (can be over 50) names in the email.  Here is a sample (not actual data).

snydertl_0-1699376925282.png

 

I know I need to do a split from the Name: text and take the content after the Name: and put it in an array variable, but I can't make it work.

 

Any help would be appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
snydertl
Frequent Visitor

One of my coworkers came up with a solution that was a bit crazy but works!

1. When new email arrives - find based on Subject

2. HTML to Text - convert body to text

3. Initialize variable - string to hold the names 

snydertl_0-1700672205170.png

4. First Compose - expression - last(split(body('Html_to_text'),'BUSINESS PERSONAL')) 

Business Personal was a line in the email before the table with the name information.

 

5. Compose - expression - 

uriComponentToString(replace(uriComponent(outputs('Compose')), '%0A'''))
 
Believe this is to get rid of spaces from the output of the Compose above.
 
6. Compose - expression - 
split(replace(outputs('Compose_4'),'    Name',';Name'),';')
 
This is modifying the output from the Compose in step 5
 
7. Filter Array - Take output from Compose in step 6.  Filter out anything that is empty - 
empty(item())
snydertl_1-1700672450536.png

8. Apply to Each - take the body from the Filter Array.

9. Compose - expression - 

replace(first(split(items('Apply_to_each'),'Personnel')),'Name:','')
 
10. Set Variable - set the variable you initialized in Step 3 to contain the Output of the Compose in step 9. 
 
11. Use the names as you need.
 
I then took the names and did a lookup in Azure for their email addresses.  Then sent them an email.  That's it! Hope this helps someone else!
 

View solution in original post

6 REPLIES 6

@snydertl 

You could do the following:

 

1) Use split() function using delimiter "Name:"

Power Automate Split Function Explained With Examples (zeitgeistcode.com)

This will return an array of strings, each representing a new hire just with the "Name:" missing at the start

 

2) Encodian's Utility - Extract Text between Values action allows you to easily parse the name:

AlexEncodian_0-1699385877799.png


Set up the parameters with Start Value Blank (i.e. start value is the beginning of the string) and the end value as "Personnel No.:"

This will extract the string. You can choose to trim the result (removes whitespace incl line breaks from the result):

AlexEncodian_1-1699386008125.png


Loop through the array of strings and repeat step 2.

Note, Encodian will soon release an action: "Utility - Extract All Texts between Values" so you don't have to do a split() or loop through the split() result after. You could do everything in one step.

You can also do step 2 with native parsing string expressions in Power Automate.

Is there more content before and/or after this new hire data in the email? It would be good to see an example of the full email that would come through to ensure we get what you're after.

 

Also, will it always include 13 rows of data for each person, and would the data always be in the same order? Name, Personnel No, Sub Personnel No, Home Phone, etc.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

@grantjenkins  what you see in the email snippet is just repeated for each new user, so those two sections are the full information provided for each user with ORCID being the last "field".  Here is an example of the text itself.

 

*** Automated E-Mail - Please do not reply ***

 

 

 

 

 

Report-To-Work List
November 06, 2023

 

BUSINESS PERSONAL

 

 

 

 

 

Name:

Smith, Joe Allen

Personnel No.:

01234567

Sub Personnel No.:

N/A

Home Phone:

 

Status/Employee Group:

New Hire / 1 REGULAR FULL TIME

Work Site Type:

ON-SITE 

Employee Subgroup:

E1 EXEMPT

Directorate:

Wild Systems Sci 52525252 

Division/Org Unit:

Egg Sciences Division 50000000 

Job Title:

Technical Assistant Staff Member (15151515)

Position:

Software Developer (300000000)

Citizenship:

USA

ORCID:

 

 

 

 

 

Name:

Jones, Betty Ann

Personnel No.:

0235678

Sub Personnel No.:

N/A

Home Phone:

(865)111-2222

Status/Employee Group:

New Hire / 1 REGULAR FULL TIME

Work Site Type:

ON-SITE 

Employee Subgroup:

E1 EXEMPT

Directorate:

National Kitten Directorate 65498754 

Division/Org Unit:

Kitten Proliferation Division 12345857 

Job Title:

Technical Assistant Staff Member (5546789)

Position:

Full Kitten Developer I (11111111)

Citizenship:

USA

ORCID:

 

 

 

 

 

Name:

Doe, Martha 

Personnel No.:

03456789

Sub Personnel No.:

N/A

Home Phone:

(865)222-3333

Status/Employee Group:

New Hire / T TEMPORARY FULL TIME

Work Site Type:

ON-SITE 

Employee Subgroup:

E1 EXEMPT

Directorate:

CC Sciences Dir 12345678 

Division/Org Unit:

Really long name Scienc 55555555 

Job Title:

Post Doc (51515151)

Position:

Postdoctoral Research Associate - Advanc (20000000)

Citizenship:

Peru

ORCID:

0000-0003-1111-2222

 

 

 

 

 

@AlexEncodian 

Thank you for the answer, however, my cyber security department will not allow third party connectors. 

snydertl
Frequent Visitor

One of my coworkers came up with a solution that was a bit crazy but works!

1. When new email arrives - find based on Subject

2. HTML to Text - convert body to text

3. Initialize variable - string to hold the names 

snydertl_0-1700672205170.png

4. First Compose - expression - last(split(body('Html_to_text'),'BUSINESS PERSONAL')) 

Business Personal was a line in the email before the table with the name information.

 

5. Compose - expression - 

uriComponentToString(replace(uriComponent(outputs('Compose')), '%0A'''))
 
Believe this is to get rid of spaces from the output of the Compose above.
 
6. Compose - expression - 
split(replace(outputs('Compose_4'),'    Name',';Name'),';')
 
This is modifying the output from the Compose in step 5
 
7. Filter Array - Take output from Compose in step 6.  Filter out anything that is empty - 
empty(item())
snydertl_1-1700672450536.png

8. Apply to Each - take the body from the Filter Array.

9. Compose - expression - 

replace(first(split(items('Apply_to_each'),'Personnel')),'Name:','')
 
10. Set Variable - set the variable you initialized in Step 3 to contain the Output of the Compose in step 9. 
 
11. Use the names as you need.
 
I then took the names and did a lookup in Azure for their email addresses.  Then sent them an email.  That's it! Hope this helps someone else!
 

Hi @snydertl. Sorry for not getting back to your post. Just for reference, this is how I'd have built it.

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1700751194628.png

 

When a new email arrives triggers on new email.

grantjenkins_1-1700751220691.png

 

Html to text converts the body of the email to text.

grantjenkins_2-1700751249729.png

 

Filter array extract the data and splits on new line, then removes any empty rows of data.

//From
split(last(split(outputs('Html_to_text')?['body'], 'BUSINESS PERSONAL')), decodeUriComponent('%0A'))

//Condition
trim(item())

grantjenkins_3-1700751342647.png

 

Compose contains an expression to extract out all the names into an array. It converts the data to XML then uses XPath to get the names.

xpath(
    xml(json(concat('{"root": { value:', body('Filter_array'), '}}'))), 
    '//root/value[. = "Name:"]//following-sibling::value[1]/text()'
)

grantjenkins_4-1700751536889.png

 

After running the flow we would get the following output.

grantjenkins_5-1700751576259.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,424)