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 / Renaming a File in Sha...
Power Automate
Unanswered

Renaming a File in SharePoint - with an Incremental number at the beginning of the file name

(1) ShareShare
ReportReport
Posted on by 4
Hello Community

I have read through similar threads in this forum and although there are several threads, most are unanswered. The threads that have answers aren't similar to what I am trying to do.
 
I am relatively new to PowerAutomate and can find my way around pretty well, except this latest flow I have been trying to create has got me stumped.
 
I require support in refining my current flow so that:
 
When a file is created in SharePoint > a set of actions modifies the name of the file - ensuring that a sequential (incremental number is added to the beginning of the file.
Case: There are already 62 files in the current folder. The Imported file name is Posting GL FilePE01.09.2024.xlsx, The output I require is: 63. Posting GL File PE 01.09.2024.xlsx (adding the incremental file number at the start and adding a gap between PE and the date).
 
So far, I have the below. Note that I have redacted the library and folder names and those fields aren't actually empty.
 
 
In the image below:

Value = 
 
Items - 
 
Concat = 
 
In Create File = Output = Output from the Construct New File Name step
In Create File = File Content = Body from the Get File Content step
 


End Result: Always fails at the Construct New File Name step.
InvalidTemplate. Unable to process template language expressions in action 'Construct_New_File_Name' inputs at line '0' and column '0': 'The template language expression 'concat(variables('IncrementalNumber'), '. ', items('Apply_to_each')['FileLeafRef'])' cannot be evaluated because property 'FileLeafRef' doesn't exist, available properties are '@odata.etag, ItemInternalId, ID, Modified, Editor, Editor#Claims, SharedWithUsers, SharedWithUsers@odata.type, SharedWithUsers#Claims, SharedWithUsers#Claims@odata.type, MediaServiceImageTags, MediaServiceImageTags@odata.type, MediaServiceImageTags#WssId, MediaServiceImageTags#WssId@odata.type, Created, Author, Author#Claims, OData__DisplayName, {Identifier}, {IsFolder}, {Thumbnail}, {Link}, {Name}, {FilenameWithExtension}, {Path}, {FullPath}, {IsCheckedOut}, {DriveId}, {DriveItemId}, {VersionNumber}'. Please see https://aka.ms/logicexpressions for usage details.'.
 
 
Need some help please. I am sure there is a simpler way to do this that I am not aware of.
 
Regards
 
Categories:
I have the same question (0)
  • Suggested answer
    creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at
    You need to use the Get File Properties action (singular). This action returns a single file. In your current flow you are using the Get File (Properties Only) action. While this isn't wrong, this action will return an array of items—even if it's a single item. This is why your current flow has an Apply to Each action. 
     
    This action is only require if you are looping through multiple items. Since your flow is being triggered when a file is created, you should only return the properties of the file created. 
     
    Also, the FileLearRef property is used in the OData Filter Query. The error states the following: 
    InvalidTemplate. Unable to process template language expressions in action 'Construct_New_File_Name' inputs at line '0' and column '0': 'The template language expression 'concat(variables('IncrementalNumber'), '. ', items('Apply_to_each')['FileLeafRef'])' cannot be evaluated because property 'FileLeafRef' doesn't exist, available properties are '@odata.etag, ItemInternalId, ID, Modified, Editor, Editor#Claims, SharedWithUsers, SharedWithUsers@odata.type, SharedWithUsers#Claims, SharedWithUsers#Claims@odata.type, MediaServiceImageTags, MediaServiceImageTags@odata.type, MediaServiceImageTags#WssId, MediaServiceImageTags#WssId@odata.type, Created, Author, Author#Claims, OData__DisplayName, {Identifier}, {IsFolder}, {Thumbnail}, {Link}, {Name}, {FilenameWithExtension}, {Path}, {FullPath}, {IsCheckedOut}, {DriveId}, {DriveItemId}, {VersionNumber}'. Please see https://aka.ms/logicexpressions for usage details.'.

    You need to use the Name Dynamic Content in your Compose action.

    Also, if your flow doesn't already have trigger conditions set up—I'd recommend that you consider using Trigger Conditions in your flow. This way your flow is only triggered when the files are created (not folders) and when files that meet your criteria are created. Trigger conditions can prevent your flow from unnecessarily triggering.

    You may be interested in these YT Tutorials:

    If you are using an Automated Cloud flow trigger in your flow—you need to consider adding trigger conditions.
    Do YOU 🫵 know what a trigger condition is?

    Trigger conditions can be set in most flow triggers. These conditions you set must be true for the trigger to fire.
    In this Power Automate tutorial, I’m going to show you how to use trigger conditions in your flows to control when your Power Automate flows trigger. If your plan has flow run limits—you can avoid triggering your flows unnecessarily by using trigger conditions.
    I’ll cover four different flow examples that would benefit from trigger conditions:

    ⚡️ Triggering a flow when a column is changed to a specific value
    ⚡️ Triggering a Flow When an Event Updated or Deleted
    ⚡️ Triggering a Flow When a New Folder is Created
    ⚡️ Triggering a Flow When a Specific Email is Received

    I’ll also show you a trick on how to easily create the expressions needed and give you a few tips on how to troubleshoot your flow.

    IN THIS VIDEO:
    ✓ Four different flows that would benefit from trigger conditions
    ✓ What is a trigger condition?
    ✓ How to add a trigger condition to your flow
    ✓ How to trigger a flow when a column is changed to a specific value
    ✓ How to trigger a flow when an event is updated or Deleted
    ✓ How to trigger a flow when a new folder is created
    ✓ How to trigger a flow when a specific email is received
    ✓ How to troubleshoot a trigger condition
    ✓ How to prevent case sensitivity issues with a trigger condition
    ✓ How to use the filter array action to easily compose an expression that can be used in a trigger condition

    ----

    3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow
    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:
    1️⃣ Looping through a Single Item
    2️⃣ Creating Unnecessary Nested Loops
    3️⃣ Looping through an Unfiltered Array


    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.


    IN THIS VIDEO:
    ✓ How to avoid the Apply to Each action with a single item array
    ✓ How to use the item() function to access dynamic content in an array
    ✓ How to prevent unnecessary nested Apply to Each action loops
    ✓ How to use the Select action
    ✓ How to convert an array to a string with the Select action
    ✓How to use the Filter Query field
    ✓ How to count the number of items in an array
    ✓ How to use a condition control
    ✓ How to use the concurrency control
    ✓ How to set a top count
    ✓ How to use Compose actions for troubleshooting

    Hope this helps!

     

  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,325 Super User 2025 Season 2 on at
    Hi
     
    The reason they are mostly not answered, and I have answered plenty, is that there is NO way to guarantee that the number will be unique. So I am not going to tell you how to fix what you tried because its not, unfortunately relevant to why people do not answer. Even though its been stated (by myself tons and others, that its not possible to really do perfectly).
     
    Why? Because the entire platform is multi-threaded and if 2 or 3 triggers happen at the same time, you are absolutely going to see it duplicate names.
     
    So now I will tell you how i would do it and do with it what you will.
     
    You already have a perfect number to use, the ID column of the SharePoint Document Library. It is gauranteed to be unique
    Its there for you, when the file is created, so instead of trying to rename it and figure out how to force the system to give you uniqueness, use the one that already does it for you.
     
    concat('dynamicIDProperty', '_', 'OriginalName', 'extensionIfyoudidnthaveitintheoriginalnamecolumn')
     
    Done.
     
     
     
  • Suggested answer
    CU21090536-0 Profile Picture
    4 on at
    Thank you to FLMike and creativeopinion for your replies.
     
    I ended up solving my issue by simplifying what I was doing.
     
    I now have a redundant folder where the original file is sent to (from a different flow). When the file is created in the folder. the below flow kicks in.
     
    1. When a file is created (properties only)
    2. Get files (properties only)
    3. Compose
    4. Compose
    5. Compose
    6. Compose
    7. Get file content
    8. Create file
    9. Delete file
     
    End result was new file in destination folder with an incremental number added to the beginning of the file.
     
    If anyone ever finds this thread and in need of details, let me know.
     
     
    Thank you

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

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard