ashveli
ashveli

Reputation: 288

Dynamics CRM 2011 - Adding Lookup Value?

I'm developing a windows forms application & I've retrieved all the values from the look up by using the following code:

var value = item.GetAttributeValue<EntityReference>("attributename").Name;

Now comes the major task of assigning a value to the Lookup fields. When I tried to add the value it fails. I browsed in the internet and there is not much info about this. I could only find some Xrm.Page which is for web applications.

Can anyone of the experts please help on this & shred some light upon?

Upvotes: 0

Views: 88

Answers (1)

Dave Clark
Dave Clark

Reputation: 2311

Create a new entity object, set the attribute values you want (in this case an EntityReference) and then finally call Microsoft.Xrm.Sdk.IOrganizationService.Update.

  1. Create a new entity object

    var entity = new Entity { Id = new Guid("recordId"), LogicalName = "entityName" };
    
  2. Set attribute values

    entity["attributeName"] = new EntityReference(new Guid("recordId"), "entityName");
    
  3. Call update

    service.Update(entity);
    

Upvotes: 3

Related Questions