Assign owner of a record in Microsoft Dynamics CRM using C#

Hi all,

There are few  scenarios in Microsoft Dynamics CRM where we come across to assign the owner of a record pro-grammatically using C# to achieve the business requirement.

Recently i came across a scenario from my client where i need to assign the owner of a Manufacturer(User/Team level entity) based on the channel(Lookup) in Microsoft Dynamics CRM.

In order to achieve this , Microsoft has provided us with AssignRequest class in Microsoft Dynamics CRM.

Assign Request Class :

AssignRequest assign = new AssignRequest
    {
        Assignee = new EntityReference("systemuser",
            new Guid("userguid")),
        Target = new EntityReference("TargetEntity",
            "TargetentityrecordGuid")
    };


// Execute the Request
service.Execute(assign);

Sample Code :

AssignRequest assign = new AssignRequest
    {
        Assignee = new EntityReference("systemuser",
            new Guid("9245fe4a-d402-451c-b9ed-9c1a04247482")),
        Target = new EntityReference("new_manfacturer",
           new Guid("8245fe4a-d402-451c-b9ed-9c1a04247482"))
    };


// Execute the Request
service.Execute(assign);

Hope this helps 🙂

 

Advertisements

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