GUID stands for Global Unique IDentifier, and it’s a market standard that is represented by “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx “. Alternatively, since the structure is always the same, you can represent it without the hyphens, like “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” It’s a strange structure, but you can read more here if you want to understand what each section means. The GUID function helps us in two ways. First, we can try to convert a string to a GUID object or generate a new GUID.
Let’s explore it a bit more.
It follows a simple pattern.
- String (optional)
GUID('66a7dc02-d9c7-4c2d-812a-383fe8cf3748') will return an object with '66a7dc02-d9c7-4c2d-812a-383fe8cf3748'
Notice that, although they look the same, they are different objects, meaning that they react differently depending on what you do with them.
Now let’s call the GUID function without any parameter.
GUID() will return an object with '123e4567-e89b-12d3-a456-426655440000'
A new GUID is generated.
The question now is, why use it? There are a lot of places where you want to have a unique identifier for a record. Although Power App does a great job to abstract this from the UI, you may need to create one if:
- You deal with the CDS (Microsoft’s common data services), and you need to generate the keys
- Deal with databases in general. Some require that you generate the ids yourself, so you may need to use the GUID function, depending on the datasource.
- Deal with APIs. Some APIs need you to provide GUIDs to identify objects, for example.
I understand that the usage is not frequent, but it’s important to know what they are.
The GUID function is volatile, meaning that when used without parameters, it will return a different value each time it’s evaluated. So you’ll get a new GUID each time you call the function.
It’s important to understand that we’re talking about hexadecimal values, so the possible values are between 0 and 1 and “a” to “f”. For example:
Microsoft typically uses the lowercase representation to avoid issues (there’s a great post in Microsoft’s Blog about this), but GUIDs are case-sensitive, meaning that the following GUIDs are different:
123e4567-e89b-12d3-a456-426655440000 123E4567-E89B-12D3-A456-426655440000 123E4567-e89b-12d3-a456-426655440000
Be very careful and define a strategy for your organization because this can generate a lot of issues if not dealt with correctly.
Don’t touch the hyphens.
Since the hyphens are optional, you don’t need to add them, so don’t try to do it. Also, if there are hyphens in the GUID object, leave them alone. The GUID function and Power Apps do a great job converting things in the background, so don’t worry about it.
Back to the Power Apps Function Reference