dynamics-crm-2011dynamics-crm

Set a lookup field using Plugin in Dynamics CRM


How to Set a value for lookup field using Plugin in Dynamics CRM? I am using the code below but it is NOT working.

Entity ent = (Entity)service.Retrieve("mdoc_sentence", sGUID, new ColumnSet(new string[]{ "lookupFiled"} );

ent["lookupFiled"] = "baa25488-6d99-es11-99da-225056836fb7";

service.Update(ent);

Solution

  • You should use following code:

    ent["lookupfield"] = new EntityReference("entityname", new Guid("baa25488-6d99-es11-99da-225056836fb7"));