Get and set a Dataverse lookup column

The post provides sample code snippets for interacting with Dataverse’s lookup data type column in C# and JavaScript / TypeScript

Example scenario – multiple customer records associated to a company record

There is a N:1 relationship between the customer table and the company table. Within the customer table, there is a simple lookup data type column. This column contains three values which associate it to it’s parent record (a company record in this case).

  • the id of the company record
  • the entity type of the record e.g. account
  • the name of the record e.g. Contoso Pharmaceuticals Limited

In C#

Get a lookup column

Set a lookup column

Microsoft.Xrm.Sdk.EntityReference object

In JavaScript / TypeScript

Get a lookup column

The companyEntityRef record (refer to the code below) is constructed from the results of a retrieveRecord Web API call (retrieve a customer record containing the lookup to company)

(See the common function in the appendix.)

Set a lookup column

or

(See the common function in the appendix.)

In Power Automate

Set a Dataverse lookup data type column in Power Automate

Appendix

TypeScript common functions

References

https://learn.microsoft.com/en-us/power-apps/maker/data-platform/types-of-fields