Tuesday, September 12, 2017

Update Lookup field from CRM Plugin

I have recently came across a situation where need to update a lookup field in my CRM Plugin.

I had found two ways, kind of similar, which will does the things.

For CRM Lookup field, when accessing from Plugin, is a Entity Reference so need to create an object of that with guid and update the entity with that object will does the trick.

Example:1:

Entity entity = new Entity();
entity = service.Retrieve("new_entityname", new Guid(guid), new ColumnSet(true));
entity["new_fieldName"] = new EntityReference("new_status", statusId);
service.Update(entity);

Example:2:

Entity entity = new Entity("new_entityname",guid);
entity["new_fieldName"] = new EntityReference("new_status", statusId);
service.Update(entity);

Where,
guid = guid of the Entity
new_fieldName = schema name of field
new_entityname = schema name of Entity
new_status = schema name of  lookup field
statusId = guid of the lookup field record

Questions/comments/suggestions? please put it in comments below post for further discussion!!!

Follow By Email for more updates directly into your inbox...

No comments:

Post a Comment