Thursday, August 23, 2012

Plug-in to Update Associated(lookup) record in CRM 2011

On Case form we can see the lookup which is pointing to Customer (Contact and Account). Lets assume a scenario -when user create a Case record, the related customer record has to be updated by setting a custom field flag to True, which indicates the Customer is associated with Case.
Below is the C# code to achieve this functionality using plug-in on Case creation.



using Microsoft.Crm.Sdk.Messages;

EntityReference customerEntityReference = (EntityReference) caseEntity.Attributes["customerid"];

if(customerEntityReference !=  null && customerEntityReference.Id != Guid.Empty)
{
    Entity customerEntity  =  new Entity(customerEntityReference.LogicalName);
    customerEntity.Id = customerEntityReference.Id;
    customerEntity.Attributes["new_caseassociatedflag"] = true;
    service.Update(customerEntity);
}


No comments:

Post a Comment