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 / Generate Unique docume...
Power Automate
Unanswered

Generate Unique document ID in a sharepoint library

(0) ShareShare
ReportReport
Posted on by

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 

Categories:
I have the same question (0)
  • v-yamao-msft Profile Picture
    on at

    Hi @Anonymous,

     

    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-the-rest-interface 

     

    Best regards,

    Mabel

  • ScottShearer Profile Picture
    25,270 Most Valuable Professional on at

    @Anonymous:

     

    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

     

     

  • Community Power Platform Member Profile Picture
    on at

    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".

     

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