
Announcements
Hi, good day! i just want your expert opinion and help about this flow, this is already running but i think there must be a better way.
I am writing to explain the Power Automate flow that I have created for generating unique reference numbers based on the service requested by the user.
The purpose of this flow is to allow users to create a unique reference number for their requested service. The reference number is generated based on the service they selected, and it follows a specific format.
For example, "FMA-TT-YYYYMM-00000" is used for the Trip: Driver and Service Vehicle service, "FMA-MS-YYYYMM-00000" is used for Messengerial service, and "FMA-UA-YYYYMM-00000" is used for Utility Assistance.
The flow begins by checking the service that the user has requested and setting the format of the reference number accordingly. It also checks if the created date is the same as the current year and month (YYYYMM). If it is not, the reference number will reset to 00001. If the created date is the same, the flow will get the last recorded reference number and add 1 to it.
For example, suppose there are three recorded reference numbers: 00001, 00002, and 00003. If we delete 00002, the next ticket will be 00004. Similarly, if we delete 00001 and 00002, the next ticket will be 00003.
If the reference number is empty, the default value will be set to 0001. Moreover, the flow will check if the reference number already exists. If the reference number already exists, it will enter a loop to generate a unique reference number.
Finally, the flow creates an item as the last step.
In conclusion, this Power Automate flow allows users to generate unique reference numbers based on their requested service. It ensures that the reference numbers are formatted correctly and are unique for each request.
Since you are just asking for opinions, I think what you are trying to do is overly complicated. I don't know how you will keep track of the incrementing number that will be part of the ID if you need to take into consideration deleted items. I am assuming that your flow runs when the item is created, so I am not following why you need to check if the current year and month is the same as the created date. How could it not be? If it is because you want the numbers to start over each month at zero, again, that is going to be very complicated. I would assess how beneficial that really is.
To greatly simplify what you want to do, I would use the ID of the list item for your unique reference number. In SharePoint, the ID is basically a primary key and can never be used again. If an item is deleted, it will automatically create the next item with the next logical number. You can easily format the ID with leading zeros with the following expression:
formatNumber(triggerOutputs()?['body/ID'],'000000')