Power Automate: relate CDS records

Why?

When you have entities in the Common Data Service (CDS) that are related to each other, every now and then you will want to relate records of these entities using a Power Automate Flow. 🖇

What?

Unfortunately this is not as straight forward as just using the unique identifier of the record (GUID) in the related lookup column… so let’s see how we can achieve this!

How?

In my example I have an entity representing Approval Steps. This entity is related to the default Users entity, storing the Approver of the Approval Step:

I use a variable because in a Switch above the Approver is found based on different business rules. However the logic is always the same: when using only the unique identifier (GUID) of the User Entity to link the records, it will result in an error:

❌ “Resource not found for the segment(…)” ❌

1) We need to use a specific notation: [entity name in plural]([GUID of the record]). This notation can be retrieved from the record properties and is found when searching for odata.editLink.

In my example the actual value of the default Users entity needed to link:

systemusers(acbea0ad-fb09-eb11-a813-000d3a4b220c)

When using the Get a record-action, we can use the following expression to get this needed notation:

first(split(last(split(body('Get_a_record_-_ApprovingUser')?['@odata.editLink'],'')),','))

When using the List records-action, we can use the following expression to get the needed notation from the first record listed:

first(split(last(split(first(outputs('List_records_-_ApprovingUsers')?['body/value'])?['@odata.editLink'],'')),','))

Now you can use one f these formulas in the Lookup Column of the Power Automate Action and the records will get linked by the flow 💪

I will add these expressions also to my blog post about Power Automate: Handy Expressions 👍

Leave a comment