cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Parsing Multiple (Varied Amount) of Lines from Email into Excel Table

I have posted on many occasions around half a year ago, on this and similar forum pages, yet ultimately failed in obtaining a defined solution. I have decided to tackle this again in hope I can achieve my goal. 

 

To give a breakdown of my problem I will first post the threat which brought me closest to an answer: 

Solved: Parse multiple lines of email with same data struc... - Power Platform Community (microsoft....

There are many other tutorials I have viewed on Youtube, but most of them come in the form of emails that have been restricted for the owners need. for example a form in which a user fills out and the email is delivered which set values such as:

 

Name: XXXXX

Age: XX

Location: XXXXX

 

Name: XXXXX

Age: XX 

Location: XXXXX

 

The difficulty I have, is that I'm trying to parse values from an email in which the response cannot be manipulated (Office 365 Endpoint Notifications). One day I may receive an email containing details of one vulnerability, the following week I may contain an email which has details of 5 vulnerabilities. When I use 'HTML to text' the values are delivered like so:

 

VULNERABILITIES DETAILS

 

Vulnerability Name

 

CVE-2092-9000

 

Severity

 

High

 

CVSS

 

9

 

Exposed devices

 

102

 

Affected products

 

Microsoft Teams

 

 

 

Vulnerability Name

 

CVE-3000-2112

 

Severity

 

Medium

 

CVSS

 

7.9

 

Exposed devices

 

99

 

Affected products

 

Zoom Meetings

 

 

 

Vulnerability Name

 

CVE-1721-3033

 

Severity

 

Medium

 

CVSS

 

7.5

 

Exposed devices

 

2

 

Affected products

 

Windows 2000 Server  

 

 

 

 

 

 

 

 

 

 

 

\"Facebook\"

[\"https://images.ecomm.microsoft.com/cdn/mediahandler/azure-emails-templates/production/shared/images/..."]

 

There are some links etc prior to the 'VULNERABILITY DETAILS' heading I have left out, but to aid your solution, I know that I only want the values after 'Vulnerability Details' and before '\"Facebook\" where a Facebook logo is added. I need to grab each of the values below 'Vulnerability Name', 'Severity, 'CVSS', 'Exposed Devices' and finally 'Affected Products'. Each value is located one line space below each heading, and again the number of values may vary from one email to another.

 

So my end goal, is to have a flow which parses each value of the email and adds that value into a corresponding table within excel - I would like each group of values to be added into a row, then a new row to be added for the next group of values until finally we reach the \"Facebook\" wording which indicates there are no more values to be grabbed. I believe this would be easier if it was laid out such as:

 

Vulnerability Name:  CVE-1721-3033

Severity: High

CVSS: 7.5 

 

But again this cannot be altered. I require a flow to loop through and store each set of values into excel per row, until all the contents I require have been captured and documented. Like before, I'm not expecting anyone to come up with a solution to this, but I will offer an abundance of feedback and support to clarify and bridge confusion amongst my post. Any existing articles or topics answering this would also be appreciated if stated, but I can assure I'll have likely viewed most of them. 

 

To give a starting point, I can confirm the wording 'VULNERABILITY DETAILS' always starts at line 47 of each email, though the wording \"Facebook\" line ends at will vary depending on the amount of vulnerability info received prior. I also know something similar to a split/skip function could be applied to miss a blank line of text between each heading and the value I need 2 lines below - but other than that I only have a basic understanding. The Excel sheet being used has each of the headings per column, once each row is filled a new row should be added to log the next set of values, and so on.

 

Any support of guidance is appreciated, this is one of the things I can't let lie as I know it is possible once someone with an abundance of knowledge in this field can shed any light. Thank you in advance, feel free to message me any questions relating to this post or the email being received. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@MDE94 Hopefully this will get what you're looking for.

 

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

grantjenkins_0-1672972391663.png

 

Compose contains your data that you get after you've used HTML to text. I didn't have the raw data so had to start from here.

grantjenkins_1-1672972472160.png

 

Filter array uses a fairly long expression to give us an array of items. The expressions used are below. The first expression uses slice to retrieve the data we want including the VULNERABLILITIES DETAILS. We then split on new line then remove the first line using skip. 

//From (input)
skip(split(slice(outputs('Compose'), indexOf(outputs('Compose'), 'VULNERABILITIES DETAILS'), indexOf(outputs('Compose'), '\"Facebook\"')), decodeUriComponent('%0A')), 1)

//Condition
trim(item())

grantjenkins_2-1672972576638.png

 

This would give us the following output.

grantjenkins_7-1672974985322.png

 

Initialize variable creates an array variable called data.

grantjenkins_3-1672972626337.png

 

Apply to each chunks the data into groups of 10 rows which is the number of rows per item in our array. The expression used is:

chunk(body('Filter_array'), 10)

grantjenkins_4-1672972706924.png

 

Append to array variable appends an object using the data from the current item to our data array. The expressions used are:

trim(items('Apply_to_each')[1])
trim(items('Apply_to_each')[3])
trim(items('Apply_to_each')[5])
trim(items('Apply_to_each')[7])
trim(items('Apply_to_each')[9])

 

The full object data is below:

{
    "Vulnerability Name": @{trim(items('Apply_to_each')[1])},
    "Severity": @{trim(items('Apply_to_each')[3])},
    "CVSS": @{trim(items('Apply_to_each')[5])},
    "Exposed devices": @{trim(items('Apply_to_each')[7])},
    "Affected products": @{trim(items('Apply_to_each')[9])}
}

 

grantjenkins_5-1672972785772.png

 

Output is a Compose that just shows the actual data stored in our data array.

grantjenkins_6-1672972895248.png

 

The output in this instance would be:

[
  {
    "Vulnerability Name": "CVE-2092-9000",
    "Severity": "High",
    "CVSS": "9",
    "Exposed devices": "102",
    "Affected products": "Microsoft Teams"
  },
  {
    "Vulnerability Name": "CVE-3000-2112",
    "Severity": "Medium",
    "CVSS": "7.9",
    "Exposed devices": "99",
    "Affected products": "Zoom Meetings"
  },
  {
    "Vulnerability Name": "CVE-1721-3033",
    "Severity": "Medium",
    "CVSS": "7.5",
    "Exposed devices": "2",
    "Affected products": "Windows 2000 Server"
  }
]


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


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

View solution in original post

7 REPLIES 7

@MDE94 Will you always have the same number of lines per Vulnerability? I mean will it only contain the following, or will there be a variable list of properties in addition to this?

 

  • Vulnerability Name
  • Severity
  • CVSS
  • Exposed devices
  • Affected products

----------------------------------------------------------------------
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 many thanks for your response, I will be going to bed soon but will reply to any further questions first thing tomorrow. But yes, each of those attributes will always be included in every email, will never be blank or missing 1 of the 5 etc. So one thing guaranteed is that 'VULNERABILITY DETAILS' opens at line 47, meaning 'Vulnerability Name' will begin at line 49 of each email after accounting the blank space in between. The email body could be split from everything prior to 'Vulnerability Details' as it isn't required, and after \"Facebook\". 

 

Some form of array could be applied to each sub set of vulnerability details as like you ask, all of those 5 headings are going to be included in each email (the email is not received at all unless one set of those 5 sub-headings are included). 

@MDE94 Hopefully this will get what you're looking for.

 

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

grantjenkins_0-1672972391663.png

 

Compose contains your data that you get after you've used HTML to text. I didn't have the raw data so had to start from here.

grantjenkins_1-1672972472160.png

 

Filter array uses a fairly long expression to give us an array of items. The expressions used are below. The first expression uses slice to retrieve the data we want including the VULNERABLILITIES DETAILS. We then split on new line then remove the first line using skip. 

//From (input)
skip(split(slice(outputs('Compose'), indexOf(outputs('Compose'), 'VULNERABILITIES DETAILS'), indexOf(outputs('Compose'), '\"Facebook\"')), decodeUriComponent('%0A')), 1)

//Condition
trim(item())

grantjenkins_2-1672972576638.png

 

This would give us the following output.

grantjenkins_7-1672974985322.png

 

Initialize variable creates an array variable called data.

grantjenkins_3-1672972626337.png

 

Apply to each chunks the data into groups of 10 rows which is the number of rows per item in our array. The expression used is:

chunk(body('Filter_array'), 10)

grantjenkins_4-1672972706924.png

 

Append to array variable appends an object using the data from the current item to our data array. The expressions used are:

trim(items('Apply_to_each')[1])
trim(items('Apply_to_each')[3])
trim(items('Apply_to_each')[5])
trim(items('Apply_to_each')[7])
trim(items('Apply_to_each')[9])

 

The full object data is below:

{
    "Vulnerability Name": @{trim(items('Apply_to_each')[1])},
    "Severity": @{trim(items('Apply_to_each')[3])},
    "CVSS": @{trim(items('Apply_to_each')[5])},
    "Exposed devices": @{trim(items('Apply_to_each')[7])},
    "Affected products": @{trim(items('Apply_to_each')[9])}
}

 

grantjenkins_5-1672972785772.png

 

Output is a Compose that just shows the actual data stored in our data array.

grantjenkins_6-1672972895248.png

 

The output in this instance would be:

[
  {
    "Vulnerability Name": "CVE-2092-9000",
    "Severity": "High",
    "CVSS": "9",
    "Exposed devices": "102",
    "Affected products": "Microsoft Teams"
  },
  {
    "Vulnerability Name": "CVE-3000-2112",
    "Severity": "Medium",
    "CVSS": "7.9",
    "Exposed devices": "99",
    "Affected products": "Zoom Meetings"
  },
  {
    "Vulnerability Name": "CVE-1721-3033",
    "Severity": "Medium",
    "CVSS": "7.5",
    "Exposed devices": "2",
    "Affected products": "Windows 2000 Server"
  }
]


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


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

You have no idea how much your time and effort has been appreciated here, I cannot thank you enough - I received many messages offering what you have provided me here under a commercial basis only. Regardless on if you can answer this next question, I will accept as a solution as I now have enough to work on. The only thing missing which I should have been clearer on, is adding each of the chunked valuables into an excel row, per group output of data. 

 

I will share an image to show the Excel table's headings: 

 

From this, the actual 'vulnerability name', 'severity' etc can be ignored - as the headings within Excel indicate each per row. for example only the: 

CVE-1721-3033
Medium
7.5
2
Windows 2000 Server

 are needed, and a new row added for the next lot of this information. ignore the heading for 'recommended actions' in the excel table as that's something I manually do myself, the main goal was to store each of the vulnerability details in a log that can be accessed at any time for review.

 

Again, don't worry if you cannot provide any guidance on how storing each set if info can be logged per heading, I assume I can create a new compose where '"vulnerability name:" is split between that word and ' , ' so only the wording between those parameters are captured, in that instance it would be just 

"CVE-2092-9000"

 which would then be stored under the column 'Vulnerability Name' within Excel. 

 

Again please do not worry if you don't have a defined solution to get around this, you have been more than helpful and gone above and beyond what I expected anyone to achieve on this forum I thank you dearly. To say any further feedback or guidance on this final step is generous would be a major understatement - I will await before accepting as a solution in case. Many thanks again @grantjenkins  

@grantjenkins following on from my previous post, I attempted to simply add each of the 

'trim(items('Apply_to_each')[9])' elements into each excel row, though this returned an error:
 
Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The inputs of template action 'Add_a_row_into_a_table' at line '1 and column '3632' is invalid. Action 'Apply_to_each' must be a parent 'foreach' scope of action 'Add_a_row_into_a_table' to be referenced by 'repeatItems' or 'items' functions.'.'.
 
I guess if those values could be grabbed as an output on their own (individually) I may be able to log accordingly 

Glad to help 🙂

 

I've restructured the original flow, so it doesn't build up an array of objects, but instead just adds them to Excel.

 

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

grantjenkins_0-1673053442278.png

 

Compose, Filter array, and the Apply to each are the same as the original flow.

grantjenkins_1-1673053487416.png

 

I've removed the variable data as we aren't storing the data in an array this time. So, within the Apply to each we iterate over each of the items and add them to Excel using Add a row into a table. The expressions used are the same as before.

//Vulnerability Name
trim(items('Apply_to_each')[1])

//Severity
trim(items('Apply_to_each')[3])

//CVSS
trim(items('Apply_to_each')[5])

//Exposed Devices
trim(items('Apply_to_each')[7])

//Affected Products
trim(items('Apply_to_each')[9])

grantjenkins_4-1673054199357.png

 

Hopefully, that gets what you're after.


----------------------------------------------------------------------
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 you sir, are a saint this is just the ticket! I've accepted your previous solution as the answer as promised. Thank you ever so much, you have no idea how long it has taken for someone to provide a definitive answer to this across three websites in total. 10/10 enjoy your weekend 🙂 

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 (909)