cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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.

 

dbSeattle 

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: Generate Unique document ID in a sharepoint library

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:

 

Utcnow(‘yyyy’)

 

Add action Get files (properties only).

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

 

length(body('Get_files_(properties_only)')?['value'])

 

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

 

concat(outputs('Compose'),'123',add(outputs('Compose_2'),1))

 

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:

1.PNG

 

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:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/set-custom-permissions-on-a-list-by-using... 

 

Best regards,

Mabel

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.
Highlighted
Super User III
Super User III

Re: Generate Unique document ID in a sharepoint library

@dbSeattle:

 

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.

 

Scott

 

 

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

Scott
Highlighted
New Member

Re: Generate Unique document ID in a sharepoint library

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

Announcements
FirstImage

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (7,261)