Hi there,
So I have been trying to the same thing and so far I managed to get an autonumbering system in power automate without the issue of having duplicates. You will need 2 fields in order to have a completely unique numbering system, 1 field where your autonumbering code will be saved and 1 field to determine the index.
It is true that you will need limit your trigger of your flow to a degree of parallelism of 1. This way the flow will execute 1 at the time generating your codes in a unique fashion.
To generate autonumbering code based years you will need quite a few steps to go through (I added a screenshot of it aswell at the bottom of the steps):
- Create your code filter variable as a string (i used concat with 3 separate compose steps to create each part of the string separately):
e.g. for deliveries: D2021- - Create an index variable as an interger that holds the numbering for that specific year initialize with 0.
- List your records of your entity (in my example deliveries)
You can filter your list by checking if the code starts with your code filter from step1
Then order by the indexcode field which will contain only the digits that come after your filter as a whole number field. Also limit your result by 1 record only to get the last record (in case you change your codes manually for some reason you can still get the last record that follows this base sequence). - Then check for the length of that list if there is 1 then get the index code using first() then set that value as your index of that year, if no item was found in case no records for that specific year exist then set the index to 0.
- Then I increment the value with 1
- and use a compose to concat the filter with the index.
As you can see in this screenshot: https://i.imgur.com/Lvpak14.png
When you create the record don't forget to set both the code and the index of the code. Otherwise this method won't work properly.
You can easily alter this setup for other values you want to include like option sets and stuff.
Advantages:
- You can still change the codes as you want
- You can easily create gaps in your codes by changing the index with one value higher
Disadvantages:
- If you changed the value you can only revert the value manually. (unless you make a separate flow to revert the value)
- Flow has to be set to a parallel degree of 1 otherwise it is possible to have multiple records with the same code.
Kind regards,
Billy Cottrell
If this post helped you click the like button and if it solved your issue please accept it as the solution!