Set a Dataverse lookup column in Power Automate
Introduction
Consider two Dataverse tables ‘Receipt’ and ‘Transaction Log’. This tables are associated to each other by and N:1 relationship, with the Receipt table containing a lookup column called ‘Transaction Log’ (Figure 1). In this post, we will be setting this lookup column to a Transaction Log record.
Steps
1.) Execute the ‘Get a Transaction Log record’ action
Firstly, it’s necessary to determine how a transaction log record is referenced in Power Automate i.e. its syntax. To do this, create a simple ‘dummy’ Power Automate flow that performs a ‘Get’ on the Transaction Log record (Figure 2)
Execute the action ‘Get a Transaction Log record’ and take note of how the transaction log record is referenced (Figure 3). That is: cpl_transactionlogs(ec1eea6b-673b-eb11-a813-000d3ad1c24a)
2.) Configure the ‘Create a receipt record’ action
The ‘Create a receipt record’ action (Figure 4) in the Power Automate flow can now be configured
This flow is triggered by a HTTP POST with a JSON payload. As we discovered in the previous step, we now know that the column paymenttransactionlog (Figure 5) will contain a value of the format ‘cpl_transactionlogs(ec1eea6b-673b-eb11-a813-000d3ad1c24a)’
Now, to configure the ‘Transaction Log’ column in the action (Figure 6), add the following expression to the column
if(empty(string(triggerBody()?[‘paymenttransactionlog’])), null, string(triggerBody()?[‘paymenttransactionlog’]))
3.) Execute the Power Automate flow
Execute the flow (Figure 4) and view the results of the ‘Transaction Log’ lookup column being populated (Figure 7)
(Note: In step 1 of this post, we performed a ‘Get’ on the transaction log. If we had decided to keep that in the flow, then we could have assigned the ‘Transaction Log’ lookup following the same format as ‘Client in Session’ and ‘Invoice’ shown in Figure 8. That is, using dynamic content.)
Further reading
Get and set a Dataverse lookup data type column
References
https://learn.microsoft.com/en-us/power-automate/dataverse/overview