Archive
Assign record (i.e., Change Owner) using CRM 2011 Plug-In
Hi,
In CRM, we cant update the “Owner” field like any other field, Assign or Changing the owner in CRM need’s an explicit service request (i.e., AssignRequest)
- This is the code to “Assign” a record to other user in Plug-In
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = null;
try
{
service = factory.CreateOrganizationService(context.UserId);
// Create the Request Object and Set the Request Object’s Properties
AssignRequest assign = new AssignRequest
{
//systemuser; i.e., User to whome you are assigning the entity to
Assignee = new EntityReference(“systemuser”, {new_owner_guid}),
//Current record which you are assigning to the user
Target = new EntityReference(context.PrimaryEntityName.ToString(), context.PrimaryEntityId)
};
// Execute the Request
service.Execute(assign);}
}
Hope it helps 🙂