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 / Get ID of most recentl...
Power Automate
Answered

Get ID of most recently created file

(0) ShareShare
ReportReport
Posted on by 203

Hey I have a flow that creates files into a Sharepoint Library, and during that flow I am trying to rename the file with some of our naming convention + some sort of unique ID.

 

So I am thinking to use the ID of the latest imported/created file in a SharePoint library and increment it by 1. 

 

Is there any way I could find the ID of the latest created file?

Categories:
I have the same question (0)
  • Verified answer
    rzaneti Profile Picture
    4,262 Super User 2025 Season 2 on at

    Hi @julienvdc ,

     

    As the file is already created, SharePoint automatically assigns an ID to it, which is unique in that Document Library. You can access it through Power Automate, and include this property in the file name if you wish:

    rzaneti_0-1715081873674.png

     

    You can find the file ID by using the "Get file metadata" action. Also, assuming that you are using "When a file is created or modified (properties only)" trigger, it already provides you with the ID as dynamic content:

    rzaneti_1-1715082172871.png

     

    Let me know if it works for you or if you need any additional help!

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

    http://digitalmill.net/ 
    https://www.linkedin.com/in/raphael-haus-zaneti/ 

  • julienvdc Profile Picture
    203 on at

    Hey @rzaneti thanks for your quick reply. Actually I don't have the ID yet, as I would like to put this ID in the name as I am creating it. So that's why I am trying to get the ID of the previously uploaded file and increment it.

  • rzaneti Profile Picture
    4,262 Super User 2025 Season 2 on at

    Hi @julienvdc ,

     

    In that case, I recommend you to create an ID control separated from the default IDs handled by SharePoint. I will share a quick example on how you can do it.

     

    Knowledge base

    For further reference, I'm sharing some blog posts that I wrote about topics discussed in this answer. It can be helpful for you or for other users that find this thread:

    - Writing expressions in Power Automate: http://digitalmill.net/2024/02/27/writing-expressions-in-power-automate/ 

    - How to extract and clean texts with Power Automate: http://digitalmill.net/2023/08/12/how-to-extract-and-clean-texts-with-power-automate/ 

    - Data types in Power Automate: http://digitalmill.net/2023/08/03/data-types-in-power-automate/ 

    - Working with variables in Power Automate: http://digitalmill.net/2023/07/03/working-with-variables-in-power-automate/ 

     

    SharePoint folder overview

    For this example, we will be working with the following SharePoint folder:

    rzaneti_0-1715118236781.png

     

    All files created inside this folder follow a default naming convention: [file name] + "_ID" + [idNumber]. In our flow, we will create a new file, and the file name must follow this same convention, receiving the first integer number after the last existing idNumber.

     

    If you want to just set the id number as file name, it will be even easier. Check my comments on the Step 2 about that 🙂 

     

    Step 1 - Get the last file created in the folder

    Start by adding a "Get files (properties only)" action, selecting the site and folder (highlighted in blue) from where you want to return the file list. As advanced parameters, set the "Order by" as "Created desc" (highlighted in yellow) and the "Top Count" as 1 (highlighted in green):

    rzaneti_1-1715118493203.png

     

    These advanced parameters will ensure that only the most recently created file will be returned. 

     

    Step 2 - Isolate the current maximum id number

    The latest created file will logically have the highest id. and we need to extract it in order to assign its value plus 1 to the file to be created inside this flow. Create an integer variable, and assign an expression to its value:

    rzaneti_2-1715118752241.png

     

    The expression is: int(last(split(outputs('Get_files_(properties_only)')?['body/value'][0]['{Name}'], '_ID'))), where you must replace "_ID" (marked in red) for any other convention of your preference. In a quick summary, this expression does the following:

    1. returns the "Name" property from the first element from "Get files (properties only)" value property (which is an array)
    2. Splits this "Name" by "_ID" and captures its last part, which corresponds exactly to the number assigned to ID (in our example, this number must be 3)
    3. As this value has a string data type, transforms it into an integer, in order to allow a future sum operation

     

    If you need additional instructions on each of the methods used in this expression, I will be happy in explaining in more details 🙂

     

    If you want to just set the ID number as file name, you can simply use int(outputs('Get_files_(properties_only)')?['body/value'][0]['{Name}']) as expression.

     

    Step 3 - Create file with new ID

    Finally, you can add a "Create a file" action and populate it with the site/folder where the file must be stored. When setting the file name, assign the name that makes sense for you (in my case, I just called it as "file"), add the "_ID" (highlighted in green), as this is part of our name convention, and add an expression right after it (highlighted in yellow):

    rzaneti_3-1715119126786.png

     

     

    The expression is: add(variables('last_id'), 1), and you must replace the text marked in red by the dynamic content of the variable created in Step 2. This expression is simply increasing the existent latest id number by 1. 

     

    Output

    The flow ran successfully:

    rzaneti_4-1715119236489.png

     

    And the file was created in the SharePoint folder with ID 4, as expected:

    rzaneti_5-1715119267691.png

     

    Let me know if it works for you or if you need any additional help!

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

    http://digitalmill.net/ 
    https://www.linkedin.com/in/raphael-haus-zaneti/ 

     

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 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard