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

Save Email Attachment - Renaming using invoice number from file contents

Hi 

I'm very new to Power Automate and I'm struggling to find a way to save invoices sent as email attachments as the invoice number found in the file. 

 

As an example an attachment file name is xxxxxx 674567 ddmmyy.pdf but I need the file saved as per the invoice number in the file for example 67456.pdf

 

Any guidance or advice would be appreciated.

 

Many thanks.

2 REPLIES 2

@AGR2 You need to use the split() function. I cover how to do use the function in this section of my YT Tutorial: 7 Functions You Need to Know | ️Expression Essentials: Part 1

 

In the full tutorial I cover 7 functions you need to know when getting started with expressions.

1️⃣ empty()

2️⃣ coalesce()

3️⃣ equals()

4️⃣ if()

5️⃣ concat()

6️⃣ length()

7️⃣ split()

 

I cover how to use these functions in expressions and I’ll also cover common mistakes when it comes to writing expressions and show you a few tips and tricks along the way.

 

As a beginner or even an intermediate flow builder—expressions can seem a bit complex at first, I’m going to try to simplify it for you. If you want to level up your flows by writing expressions—keep watching!

 

IN THIS VIDEO:

 What is an Expression?

 What is a Function?

 What Does Wrapping a Function Mean?

 How Do I Insert an Expression?

 How to Use a Compose action

 How to Navigate the Expression Builder with Arrow Keys

 How to use the Expression Tooltip

 Common Mistakes When Writing Expressions

 How to differentiate a null from an empty string

 How to Get Dynamic Content When it’s Not Listed

 How to Use a Get Item Action to Verify Dynamic Content Output

 How to Convert Strings to Lower Case

 How to Troubleshoot the if() Function

 

----

Manual Trigger

I always create a manually triggered flow when building and testing my flows. I also like to keep a copy of a manually triggered flow for testing and troubleshooting purposes at a later date. 

 

Use the Email ID of an email for testing purposes. Insert the ID into a Get Email (V2) action.

creativeopinion_0-1717167593683.png

 

Loop through Attachments

If you only ever expect a single attachment, you can avoid the Apply to Each action by using an expression. I cover how to do that in this YT Tutorial: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

 

Add an Apply to Each action to loop through the Attachments.

 

Add a Compose action to hold the Attachments Name dynamic content. This action is optional, however it helps to better understand the flow and makes it easier to reference the dynamic content in the expression. Tip: Rename your actions to keep your flow organized. This is especially important if you have multiple instances of the same action. 

 

creativeopinion_6-1717167755291.png

 

Add another Compose action to store the expression. You'll need to use the split() function. The split() function takes two parameters:

split([string to split],[separator])

 

creativeopinion_1-1717167729439.png

 

Click on the dynamic content tab and insert the output from the Compose action above (the one storing the current attachment name of the attachment that is being looped through).

creativeopinion_7-1717167774239.png

Add a comma and single quotes. Between the single quotes insert a single space. 

creativeopinion_8-1717167787831.png

Run a test. Review the outputs. The split() function will take the attachment name (string) and convert it into an array splitting the string at any spaces in the attachment name.

 

In my example I have a number in my file name and it appears on the third line. Array item index starts at [0]. This means the first item is [0], second is [1], third is [2] etc.

 

In my case, the item index for my item is [2]. 

 

creativeopinion_9-1717167814317.png

 

The first() and last() function can also be used to get the first or last item in an array (respectively). 

Get the File Extension

First, we'll need to return the file extension. Add another Compose action and insert an expression. Use the last() function. We'll use this to return the last item in the array so we can get the file extension. 

creativeopinion_0-1717186969373.png

 

Insert the output from the Compose action above. 

creativeopinion_1-1717187031536.png

Run a test. This expression should output the last line of the array. 

creativeopinion_2-1717187094676.png

To get the file extension, you'll need to split this at the period and return the last item of that array. Click on the expression label to edit it. At the start of the expression enter split with an opening parenthesis.

creativeopinion_3-1717187144321.png

Press the down arrow key to go to the end of the expression. Add a comma and a period between single quotes.

creativeopinion_4-1717187193793.png

 

Don't forget to press update and run another test. The expression should now output an array. 

creativeopinion_5-1717187245370.png

 

You need to return the last item in the array. Click on the expression to edit it and wrap the entire expression in the last function. At the start of the expression enter last with an opening parenthesis.

creativeopinion_6-1717187297823.png

 

Go to the end of the expression by pressing the down arrow key and enter a closing parenthesis.

 

creativeopinion_7-1717187309564.png

 

Run a test. Review the output.

creativeopinion_8-1717187338204.png

 

Now that you have the extension you'll need to add in the file name. You can combine everything into a single expression if you'd like. To make it easier on you, I'll recommend you insert a separate expression. Place your cursor right before the existing expression in the Compose action. 

creativeopinion_9-1717187437413.png

 

The expression field should be empty. Enter another expression. As mentioned before, my number is the third item in my array. You will need to adjust this based on your array. The third item has an item index of [2]. Remember the item index starts at [0].

creativeopinion_9-1717167814317.png

 

Insert a question mark and your item array. 

creativeopinion_10-1717187530382.png

Place your cursor at the start of the expression by pressing the up arrow key. Insert the output from the Compose action above (that contains the attachment name array). 

creativeopinion_11-1717187556693.png

Press Ok. This should insert another expression label into the Compose action. Don't forget to add a period between the two expression labels.

creativeopinion_12-1717187620372.png

 

Run a test. Review the outputs.

creativeopinion_13-1717187652279.png

 

 

To get the attachment content, refer to this YT Tutorial: Save Email Attachments to SharePoint with Microsoft Power Automate

Power Automate doesn’t have a download attachment from outlook action. In this Power Automate Video tutorial, I’ll show you how to use the Get Attachment (V2) action in combination with the Create File action to get your email attachments onto SharePoint.

 

The Create File action will overwrite any files that already exist with the same name. In this tutorial, I’ll show you how you can append a timestamp to the end of a file name to prevent your file from being overwritten.

 

I’ll also show you how to set up your flow so that you can trigger it manually while building it so you don’t need to wait for an email to arrive. At the end of the video I’ll show you how adding trigger conditions to your flow can prevent it from triggering if certain conditions aren’t met. Although the final flow uses the When a new email arrives in a shared mailbox (V2) trigger, you can use any of the When a new email arrives triggers for your flow. Adjust this flow to suit your needs!

 

IN THIS VIDEO:

 How to Automate Downloading and Uploading Email Attachments to SharePoint

 How to Use a the Get Email (V2) action

 How to Use the Get Attachment (V2) action

 How to Create Attachment Files using the Create File Action

 How to Prevent the Create File Action from Overwriting a File

 How to use Split the Filename from its Extension

 How to Append a Timestamp to a File Name

 How to use the When a New Email Arrives in a Shared Mailbox (V2) trigger

 How to use the Convert Time Zone action

 How to add Trigger Conditions to your Flow

 

 

 

Hope this helps!

If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response!

👉 Level up your Power Automate skills by checking out my tutorials on YouTube
👉 Tips and Tricks on TikTok and Instagram
AGR2
Frequent Visitor

Hi ,

Many thanks for this this is very helpful but unfortunately isn't the guidance I was hoping for. 

What I am after is help on how to read the attachment , an invoice , extract the invoice number and then save the file as a PDF with that Invoice number EG 45617.pdf .

 

Many Thanks

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