“I always get some URL error when trying to update Dataverse lookup column in a Power Automate flow, what does it want from me?”
Lookup columns are the more complicated ones to work with, no matter what datasource you use. Let it be SharePoint or Dataverse, updating lookups can be challenging. In SharePoint you must get the id of the lookup item before you can update it, and in Dataverse it’s similar, yet a bit more complicated.
Additionally to the unique id of the lookup row you’ll need also the lookup table entity name. How do you get it?
Get the table entity name and update the column
Firstly, get the url to your organisation environment. Add the ‘List rows’ action followed by a ‘Compose’ and store the ‘value’ output in the ‘Compose’ action. The reason is that the ‘List rows’ action doesn’t show the JSON it returns directly.
Run the flow and check the ‘Compose’ action in the run history. The second row will contain the url to your environment, copy it up to the /9.1/ part.
Enter the url in the browser and press Enter, it’ll show you a list of all the tables.
Go to the table with the lookup values, open its ‘Properties’, and copy its ‘Logical name’.
Search for the logical name in the list of tables.
Once found, copy the whole ‘name’ value and use it together with the row id to update the lookup field, e.g.
And that’s it, you just updated the lookup field in Dataverse. Although there’s a small problem – such update will return an error message if there’s no value to update. So let’s continue.
Remove value from a lookup column
If on the other side the column already has a value and you want to remove it, use the null expression. Not a text, an expression!
Combine it together
Now you know how to update a value and how to remove a value from the column, and you can put it together in a single expression. If there’s a value use the value, and if there’s no value use null to avoid errors.
if(empty(<guid>), null, '/<tableName>(<guid>)')
Since the <guid> will be probably a dynamic content, you’ll have to combine it with the concat(…) expression.
if(empty(<guid>), null, concat('/<tableName>(', <guid>, ')'))
In the end it might look as the example below:
if(empty(outputs('Compose_2')), null, concat('/cr09b_lookuptables(', outputs('Compose_2'), ')'))
It might be a challenge to update Dataverse lookup column with Power Automate as it has such a specific format. Additionally to the row id you need also the table logical name in plural – something that’s not visible anywhere in the user interface. But with the right url you can easily find it, and use it for the update.