Assign a record to a Team using C# in Dynamics CRM 2011

Here is sample C# code how to assign a record to a team.

       //Assign a record to a team
        private void AssignRecord(Entity TargetEntity, Guid TargetRecordID, Guid OwningTeamID, IOrganizationService orgService)
        {
            try
            {
                // Create the Request Object and Set the Request Object's Properties
                AssignRequest assign = new AssignRequest
                {
                    Assignee = new EntityReference("team", OwningTeamID),
                    Target = new EntityReference(TargetEntity.LogicalName, TargetRecordID)
                };

                // Execute the Request
                orgService.Execute(assign);
            }
            catch (Exception ex)
            {
                throw new Exception("An error occured while assinging Team to a record." + ex.Message);
            }
        }
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