简体   繁体   中英

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?

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM