Advertisements
Home > CRM 2011, Plug-Ins > Assign record (i.e., Change Owner) using CRM 2011 Plug-In

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 🙂

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: