On a recent customer engagement, we had a requirement where we needed to create an automatic reference code for each SharePoint list item that was created. For this particular scenario, the number didn't need to be incremental, just in a format that is unique. The pattern that was required was the following
Where XXX are 3 random letters and ZZZZ is a random 4 digit number.
The approach I took was the following.
- Create Microsoft Flow that triggers on create of the SharePoint list item
2. Setup a dictionary variable that holds the letters of the alphabet in an array
3. Create a variable that uses the concat and rand function to create the reference code
The actual code in the value was as follows:
The above logic is as below:
- Start with the text "TRV-"
- Add 3 random letter from the alphabet variable
- Choose a random number between 1000 and 9999
4. Update the SharePoint list item with the reference code
That was it. Really simple, straight forward and showing the capabilities of the PowerPlatform and how 'nicely' they can play together :)
Below is a screenshot of the SharePoint list with the reference numbers generated successfully. Happy customer!