Showing results for 
Search instead for 
Did you mean: 
New Member

Generate Unique document ID in a sharepoint library

I have a goal of being able to auto assign a unique, configurable, and sequencial document ID whenever a document is added to a particular SP library. 

  • All documents are the same pdf form, but, contain unique details of name date and circumstances
  • In our setting over 100 individuals will have permissions to add documents to this library
  • Some random simultanious use is expected 
  • A lesser number of individuals will have permission, and must be able, to edit any document
  • I need the flow to generate a unique ID#, beginning with the current year, and ending with a set of numbers that increase by an interval of one (1) from the last most recent document added to the library, and that ID will become the document name
  • If possible, that ID should be auto-inserted into an existing field on the form
  • The ability to change the number or remove the document from the library should be restricted to a very limited number of individuals, perhaps only a Site Collection Admin.

I hope I have not gone overboard on "needs & wants" but, being new to this, I wanted any potential responder to have enough details to know exactly what I'm looking for. Much appreciation for the help of experts and other users.



Community Support
Community Support

Hi @dbSeattle,


Do you want the flow to auto-generate an ID for a file with Current Year, a set of numbers and rename the file with the ID?

Please take the following workaround for a reference.

It is triggered by When a file is created in a folder.

Add Compose action to get current Year with the following code:




Add action Get files (properties only).

Add Compose 2, use the following code to get the total number in the library:




Add Compose 3, use the following code to generate the ID:




Add create file action to rename the file with the ID generate from the previous step.

Finally, delete the original file.

Image for your reference:



If possible, that ID should be auto-inserted into an existing field on the form

Do you want to insert the Id in a column of the library? Please use the Update file properties action to update it to the specific column.

The ability to change the number or remove the document from the library should be restricted to a very limited number of individuals, perhaps only a Site Collection Admin.

Please consider using Send HTTP request to SharePoint to set custom permissions, please check the following doc for a reference: 


Best regards,


Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User III
Super User III



Do you need the numbers to start over again at 1 the the beginning of each year?

Do you need the length of the string that is generated to be constant.  So, for example, do you need the ID to look like 2018-0001 or is it OK to have it look like 2018-1 ?


Your requirements regarding who can edit and delete documents can be handled by setting appropriate SharePoint security on the library.  It does sound like you'll need to create a custom permission level that allows people to add documents but not edit or delete them.  However, SharePoint does not offer column level security.  In other words, you cannot prevent someone who has the ability to edit the document from changing the ID.  There are a few tricks you can use to make it more difficult (make the column hidden, don't allow datasheet view, etc.) but you cannot prevent someone from editing a column if they have contribute access or greater.


Also, I agree with most of the solution proposed by @v-yamao-msft but I believe that it may generate duplicate IDs if one or more documents are deleted from the library.





If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.


Hi @ScottShearer ,


I have a similar issue and I am hesitant to start a new thread. I need a "counter" to append at the end of the following taxonomy:


yr/mm     service type code   counter

1904       123                          01

1904       123                          02

1905       123                          01

1905       456                          01

1905       456                          02

1905       789                          01


Basically, the counter resets by yr/mm and by type of service code and combined there can't be duplicates of the final unique ID - '190512301' for example. I appreciate any insight to this. I've scoured several articles but I'm having a hard time applying these 2 conditions to program a "counter".


Helpful resources

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group


Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Users online (72,831)