C# Plugin methods to get lookup values

Dynamics 365 and PowerApps have some great low code options now for citizen developers however there are still times when we need to go to a plugin.

One of these is when we need to access a deleted lookup value to update the related Table so we use the PreImage in the plugin which is not available to Flows and below is how we interact with it in the plugin.

Get Value of Lookup fields
EntityReference entref = (EntityReference)item.Attributes[attributeName];

var LookupId = entref.Id;

var logicalName = entref.LogicalName;

Set Value of Lookup fields
newAccount[attributeName] = new EntityReference(logicalName, LookupId);

Set Null Value of Lookup fields
newAccount[attributeName] = Null;

Leave a Reply

Your email address will not be published. Required fields are marked *