web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Save Email Attachment ...
Power Automate
Unanswered

Save Email Attachment - Renaming using invoice number from file contents

(0) ShareShare
ReportReport
Posted on by 2

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.

Categories:
I have the same question (0)
  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @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 Profile Picture
    2 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard