Wednesday, 11 September 2013

CRM 2011 - Add/Remove Team Members

Records within CRM 2011 can be owned by either a User or a Team. 
Using Teams within CRM 2011 are a great way of sharing records between users whom:
  • Are in different Business Units
  • Do not have the correct security role against their User record
  • Don't have ownership of the record(s) they want access too
However, the main benefit of Team ownership compared to User, is that ownership is shared by all members of the owning team, rather than a single user. Security Roles applied to that Team can elevate what a User can do when being a member.


An important part of maintaining this form of ownership, is to automate how members of a Team are added and removed, you may at times want to link certain UI actions to trigger these events. This can be done very easily from within a plugin as shown below:

  1. /* Add Users to Team */
  2. AddMembersTeamRequest addMembersTeamRequest = new AddMembersTeamRequest();
  3. addMembersTeamRequest.TeamId = Guid.Parse("831F6F02-6947-46BC-BDDF-6571075569A9");    //Team
  4. Guid[] arrMembers = new Guid[] {
  5.   new Guid("A4349C86-6475-43E6-BC1D-C3244115107C"),                                   //User 1
  6.   new Guid("8121CF3B-93B4-4907-9888-46FFAA11A169")                                    //User 2
  7. };
  8. addMembersTeamRequest.MemberIds = arrMembers;
  9. AddMembersTeamResponse addResponse = (AddMembersTeamResponse)ServiceProxy.Execute(addMembersTeamRequest);
  10.  
  11. /* Remove Users from Team */
  12. RemoveMembersTeamRequest removeMembersTeamRequest = new RemoveMembersTeamRequest();
  13. removeMembersTeamRequest.TeamId = Guid.Parse("831F6F02-6947-46BC-BDDF-6571075569A9"); //Team
  14. arrMembers = new Guid[] {
  15.   new Guid("A4349C86-6475-43E6-BC1D-C3244115107C"),                                   //User 1
  16.   new Guid("8121CF3B-93B4-4907-9888-46FFAA11A169")                                    //User 2
  17. };
  18. removeMembersTeamRequest.MemberIds = arrMembers;
  19. RemoveMembersTeamResponse removeResponse = (RemoveMembersTeamResponse)ServiceProxy.Execute(removeMembersTeamRequest);

No comments:

Post a Comment

Action Microsoft.Crm.Setup.Common.Analyzer +CollectAction failed. Fatal error during installation

When installing the Srs Data Connection (Microsoft Dynamics CRM Reporting Extensions), you may have experienced the following error: ...