How to Convert String to GUID in Power Automate

How to Convert String to GUID in Power Automate

When working with Dataverse, Dynamics 365, SharePoint, or external APIs in Power Automate, you may encounter scenarios where a GUID is stored as a string value.

Understanding how Power Automate handles GUIDs helps avoid common errors when retrieving, updating, or creating records.

---

What is a GUID?

A GUID (Globally Unique Identifier) is a unique 128-bit value used by systems such as Dataverse and Dynamics 365 to identify records.

Example GUID:

3f2504e0-4f89-11d3-9a0c-0305e82c3301 ---

Why Convert a String to GUID?

---

Using Existing GUID Strings

In most scenarios, Power Automate treats GUIDs as strings. If the value already follows a valid GUID format, it can be used directly in Dataverse actions.

Example:

variables('RecordId')

Many Dataverse actions automatically recognize the value as a GUID.

---

Using the guid() Function

Power Automate includes the guid() function, which generates a new GUID.

Expression:

guid() Important: The guid() function creates a new GUID. It does not convert an existing string into a GUID. ---

Remove Braces from GUID Strings

Some systems return GUID values enclosed in curly braces. These should be removed before passing them to Dataverse actions.

Expression:

replace(
  replace(variables('GuidString'),'{',''),
  '}',''
) ---

Extract GUID from JSON Response

If an API returns a GUID inside a JSON object, extract it using the Parse JSON action.

Expression:

body('Parse_JSON')?['id']

The extracted value can then be used directly in Dataverse or other actions.

---

Validate GUID Format

Before using a value, you can validate whether it matches the standard GUID format.

Expression:

matches(
  variables('GuidString'),
  '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}
) ---

Common Errors

---

Best Practices

---

Key Takeaways