问题
I need to update a look up field in account using xrm services of microsoft dynamics crm 2011.
Need some ideas.Pls. Help
回答1:
Lookup fields in CRM 2011 are EntityReference
, this means you need to know the LogicalName
of the entity the lookup is pointing and the Id
of the record.
Assuming you are already connected to CRM (you can use simplified connection as this example: https://stackoverflow.com/a/15930366/2191473)
you can set the lookup field using this syntax:
Entity recordToUpdate = service.Retrieve("contact", contactId, new ColumnSet(true));
recordToUpdate["parentcustomerid"] = new EntityReference("account", accountId);
service.Update(recordToUpdate);
you first get the record tu update, after set the lookup field with an EntityReference and after you save the record.
回答2:
1) Download the Developer Toolkit for CRM 2011.
2) Follow the directions to develop and deploy a plugin solution
The toolkit contains templates for plugins similar to the one you require. Guido's answer for the actual lookup modification is correct.
来源:https://stackoverflow.com/questions/22959421/adding-value-to-lookup-field-in-microsoft-dynamics-crm-2011