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!
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😀
Hi @LisKr
Here is the sample.
I have used a custom SharePoint list "AssetList" with column "Asset ID".
Flow:
1. Create an automate flow and choose trigger as "When an item is created". Set the SharePoint URL and list name "AssetList":
2. Add "get items" action to get the last item. Add filter query & Order by as shown below:
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:
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:
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:
add(int(replace(items('Apply_to_each')?['AssetID'],'PC-','')),1)
Add "Set variable" action to hold new Asset ID:
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:
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:
Output:
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.
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?
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.
stampcoin
105
Michael E. Gernaey
90
Super User 2025 Season 1
David_MA
62
Super User 2025 Season 1