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
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);
🙂