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 / Generating an ID out o...
Power Automate
Answered

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

(0) ShareShare
ReportReport
Posted on 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!

 

Categories:
I have the same question (0)
  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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.

     

  • LisKr Profile Picture
    304 on at

    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?

  • Verified answer
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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 at

    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😀

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

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard