To retreive the Guid of the Lookup entity

I have an entity which has 5 attributes. 1 of these attributes is a Lookup to another entity.

What I am trying to do with my Plugin is to retreive the Guid of the Lookup entity.

Entity entity = (Entity)context.InputParameters[“Target”];

if (entity.LogicalName == “new_producttaxrate”)

{

if (entity.Attributes.Contains(“new_product”))

{

 EntityReference ownerLookup = (EntityReference)entity.Attributes[“new_product”]; productName = ownerLookup.Name; Guid productId = ownerLookup.Id;

}

 }                                                                     (Or)

 

EntityReference customer = (EntityReference)(postImageEntity.Attributes[“customerid”]);

                                Guid GuidCustomerId = customer.Id;

                                string strTitle = postImageEntity.Attributes[“name”].ToString();// customer.Name;

 

 

Leave a comment