Add/Remove User to/from Access Team in CRM 2013 using Plugin

Access Team – Overview

Access Team is a new feature added to CRM 2013. It allows to grant specific permissions to a team/user that don’t own a record. Which makes it easy to share a record with a list of users with certain rights.

If you want to Add/remove users to/from a record’s access team programmatically in plugin, please have a look that how it works.

Fields

  • Record – Record for which you want to add users to its Access Team
  • User id – User who you want to Add to Access Team
  • Access Team Template id – The template which you want to use, as there can be more than one templates created with different rights for the same Entity.
  • Name Space – Crm.Sdk.Messages

 

Add User to Access Team


AddUserToRecordTeamRequest adduser = new AddUserToRecordTeamRequest()
{
      Record = new EntityReference(entity.LogicalName, entity.Id),
      SystemUserId = userGuid,
     TeamTemplateId = teamTemplateGuid
};
service.Execute(adduser);</p>

Possible errors:

  • Insufficient Permissions to the User being added

This is possible due to the role of the user or user’s right, i.e. in the Access Team Template if it’s checked the delete rights while the User role has insufficient permissions to delete, this error may come.

 

Remove User from Access Team


RemoveUserFromRecordTeamRequest removeUser = new RemoveUserFromRecordTeamRequest()
{
     Record = new EntityReference(entity.LogicalName, entity.Id),
     SystemUserId = userGuid,
     TeamTemplateId = teamTemplateGuid
};
service.Execute(removeUser);

2 thoughts on “Add/Remove User to/from Access Team in CRM 2013 using Plugin

Leave a comment