How to generate a unique ID in Power Automate
Use the guid() expression in a Compose action. It returns a new random ID such as c2ecc88d-88c8-4096-912c-d6f2e2b138ce each time the action runs.
What is the expression for a unique ID?
Add a Compose action. On the Expression tab, enter guid(), then select OK. The output is a text value made of 32 hex digits split by hyphens.
A GUID (globally unique identifier) is random. The chance that two flows make the same one is very small, so you can use it as a key for a row, a file name or a tracking number.
How do you change the format of the GUID?
Pass one format letter as text: guid('N'). The function follows the .NET format letters.
- guid('D') gives digits with hyphens. This is the default.
- guid('N') gives 32 digits with no hyphens. It suits file names.
- guid('B') gives the hyphen form inside curly braces.
- guid('P') gives the hyphen form inside round brackets.
- guid('X') gives hex values inside curly braces. It is rarely useful.
How do you keep the same ID for the whole flow?
A Compose action runs once. Later steps that read its output get the same value. Put guid() in one Compose near the top, then pick that output in each step that needs the ID.
If you type guid() directly into several actions, each one makes a new ID. Inside an Apply to each loop, an inline guid() makes a new ID for every item. That is right when each item needs its own ID, and wrong when the items must share one. For a value you change later, see Compose vs variable.
How do you make a short random ID instead?
Cut the GUID. The expression substring(guid('N'), 0, 8) returns the first 8 characters. It is easier to read aloud or to print on a label.
A short ID is less unique. With 8 hex characters there are about 4.3 billion values. Collisions are still rare in a small list, but check for a match before you save. Use the full GUID when you cannot check.
When should you use a counter instead of a GUID?
People cannot read or remember a GUID. For ticket numbers, order numbers or any ID a person says on the phone, use a running number such as TKT-0042. The guide on auto-number ticket IDs shows how.
For a hidden key that links two lists, or a unique file name, a GUID is a good fit. You can store it in a text column and use it as a lookup key.
Can a GUID stop duplicate records?
No. A new GUID is never equal to an old one, so it cannot detect a repeat. To block duplicates, compare a real field such as an email or an order number. See prevent duplicate entries in a SharePoint list.
You can use a GUID to name each folder or file so that two runs never overwrite each other. For a folder per item, see create a folder for each list item.
FAQ
Is guid() really unique?
In practice, yes. The value is random and the number of possible values is far larger than any flow can use. It is not a promise, so check short versions.
Does guid() return the same value if the flow runs again?
No. Each run makes a new value. If you need the same ID on a retry, store the first one in the list item.
How do I get a random number instead?
Use rand(1, 100). The start is included and the end is not, so this returns 1 to 99.
Sources
- Reference guide to workflow expression functions in Azure Logic Apps and Power Automate
- Guid.ToString method (.NET format specifiers)