Set a Dataverse lookup data type 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 an actual Transaction Log record.

Figure 1

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)

Figure 2

As illustrated in Figure 3, the transaction log record is referenced as: cpl_transactionlogs(ec1eea6b-673b-eb11-a813-000d3ad1c24a)

Figure 3

2.) Configure the ‘Create a receipt record’ action

With this key piece of information, the ‘Create a receipt record’ action (Figure 4) in the Power Automate flow can now be configured

Figure 4

The flow (in Figure 4) is triggered by a HTTP POST with a JSON payload. Within the JSON payload, the column paymenttransactionlog (Figure 5) contains the value ‘cpl_transactionlogs(ec1eea6b-673b-eb11-a813-000d3ad1c24a)’

Figure 5

Now, to configure the action (Figure 6), add the following expression to the Transaction Log lookup column

if(empty(string(triggerBody()?[‘paymenttransactionlog’])), null, string(triggerBody()?[‘paymenttransactionlog’]))

Figure 6

3.) Execute the Power Automate flow

The flow is executes which results in the Transaction Log lookup column (within the newly create receipt record) containing the entity reference to the Transaction Log record

Figure 7

That’s it!

(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.)

Figure 8

Further reading

Get and set a Dataverse lookup data type column

References

https://learn.microsoft.com/en-us/power-automate/dataverse/overview