Advertisements
Home > CRM 2011, Plug-Ins > Add or Remove users to Team programmatically in CRM 2011

Add or Remove users to Team programmatically in CRM 2011

In CRM,

  • Team is a group of users.
  • Each team must be associated with only one Business Unit (BU).
  • A team can include users from any business unit, not only the BU with which the team is associated.
  • Users can be associated with more than one team.  
  • You can get the members of Team from “TeamMembership” view
TeamMemberShip view

TeamMemberShip view

We can Add or Remove users from Team using below requests programmatically

  • AddMembersTeamRequest
  • RemoveMembersTeamRequest

Below is the code to add User(s) to a Team

AddMembersTeamRequest memberTeamRequest = new AddMembersTeamRequest();

memberTeamRequest.TeamId = teamId; //Guid of Team

// Prepare Member (i.e.,User) array to add to Team

Guid[] arrMembers = new Guid[2];

arrMembers[0] = userId1; // GUID of User 1

arrMembers[1] = userId2; // GUID of User 2

// Set MemberIds property with “arrMembers”

memberTeamRequest.MemberIds = arrMembers;

// Execute the Request

AddMembersTeamResponse response = (AddMembersTeamResponse)service.Execute(memberTeamRequest);

Below is the code to remove User(s) from a Team

RemoveMembersTeamRequest removeMemberTeamRequest = new RemoveMembersTeamRequest();

removeMemberTeamRequest.TeamId = teamId; //Guid of Team

// Prepare Member (i.e.,User) array to remove from Team

Guid[] arrMembers = new Guid[2];

arrMembers[0] = userId1; // GUID of User 1

arrMembers[1] = userId2; // GUID of User 2

// Set MemberIds property with “arrMembers”

removeMemberTeamRequest.MemberIds = arrMembers;

// Execute the Request

RemoveMembersTeamResponse response = (RemoveMembersTeamResponse)service.Execute(removeMemberTeamRequest); 

🙂

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: