Skip to main content

Notifications

Community site session details
Power Automate - Building Flows
Answered

Generating an ID out of letters and numbers in a Sharepoint list

Like (0) ShareShare
ReportReport
Posted on 7 Feb 2024 11:56:55 by 304

Hello everyone,

 

I have a list in Sharepoint online which contains all of our used PCs. There is one column called "Asset ID" for which I need a flow to auto generate an ID containing the letters "PC-" and a number, e.g. "PC-10001". Everytime a new item is created the flow should create a new ID in this schema, incrementing the number by 1.

 

But this should be done without using the out of the box ID column!

 

A colleague advised me to use the get items action, sort the already existing Asset IDs in descending order and then take the highest one and add 1 to it. But I don't get how this should be done since the ID is a string with both letters and numbers and which actions are to be used for that.

I already tried using variables and the substring method but whatever I did, it always ran into an error.

 

 

Did somebody already do a similar task and can help me?

Thanks in advance!

 

  • LisKr Profile Picture
    304 on 07 Feb 2024 at 14:24:10
    Re: Generating an ID out of letters and numbers in a Sharepoint list

    Thank you very much, it works perfectly fine now!

     

    Seems like I had a quite good approach in the beginning, but just didn't know how to properly implement it. Now it seems pretty logical😀

  • Verified answer
    ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 07 Feb 2024 at 13:33:11
    Re: Generating an ID out of letters and numbers in a Sharepoint list

    Hi @LisKr 

     

    Here is the sample.

     

    I have used a custom SharePoint list "AssetList" with column "Asset ID".

    ManishSolanki_0-1707311156216.png

     

    Flow:

    1. Create an automate flow and choose trigger as "When an item is created". Set the SharePoint URL and list name "AssetList":

    ManishSolanki_1-1707311311580.png

     

    2. Add "get items" action to get the last item. Add filter query & Order by as shown below:

    ManishSolanki_2-1707311456270.png

    Filter query:

    ID ne @{triggerOutputs()?['body/ID']}

    Order by:

    ID desc 

    Top Count:

    1

     

    Add "Initialize variable" action to declare a variable that will store the Asset ID for new list item:

    ManishSolanki_3-1707311590103.png

     

    Add condition action to check if get items return any item. We will use expression to get the length of value object from get items action:

    ManishSolanki_4-1707312035008.png

    length(outputs('Get_items')?['body/value'])

     

    In "Yes" block, we will add "Apply to each" action pass the output value object array as its input. Withing that block, we will add "Compose" action to get the numeric part and increment it using expression:

    ManishSolanki_5-1707312196869.png
    add(int(replace(items('Apply_to_each')?['AssetID'],'PC-','')),1)

    Add "Set variable" action to hold new Asset ID:

    ManishSolanki_6-1707312296717.png

    Copy & paste below in the value:

    PC-@{outputs('Compose')}

     

    In "No" block, add "Set variable" to set the initial value of Asset ID, if no list item found:

    ManishSolanki_7-1707312434298.png

    Value: 

    PC-1001

     

    Finally, close "Condition" action and add "Update item" to set the asset ID. Pass the ID from the trigger and set variable in the "Asset ID" column:

    ManishSolanki_8-1707312569365.png

     

     

    Output:

     

    ManishSolanki_9-1707312666782.png

    Pls note that the flow may not function properly for bulk addition of items in SharePoint list as flow takes time to trigger & update the asset ID column.

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • LisKr Profile Picture
    304 on 07 Feb 2024 at 12:43:02
    Re: Generating an ID out of letters and numbers in a Sharepoint list

    That sounds quite good, thanks. I only don't really get what you mean with the following:

     


    @ManishSolanki wrote:

    Hi @LisKr 

     Using expression, get the "Assest ID" of first element from the output of "Get items". 

     


    How exactly do I write this and in which action do I put this? Maybe compose?

     

    And what about the following functions split and add, do I put them in a compose action and if yes only in one or do I need to create a new action for each of these functions?

  • ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 07 Feb 2024 at 12:23:58
    Re: Generating an ID out of letters and numbers in a Sharepoint list

    Hi @LisKr 

     

    In "Get items" use sort option to sort by ID in descending order to get the most recent item from SharePoint list. Set Top parameter as 1 to get only a single record as output. Using expression, get the "Assest ID" of first element from the output of "Get items". Using replace or split function remove "PC-" and extract the number. Increment the number using add function and then finally concatenate with "PC-" to get the new ID.

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 105

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 90 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 62 Super User 2025 Season 1

Overall leaderboard
Loading started