CRM 2011 – Team sharing in Plug in
Hi,
Below is the code to Share/Unshare a record to Team using “GrantAccessRequest“.
//Sharing a Record to Team
using Microsoft.Crm.Sdk.Messages;
private void ShareRecordToTeam(IOrganizationService service, Guid sharingRecordId, Entity objTeam)
{
GrantAccessRequest grantRequest = new GrantAccessRequest()
{
Target = new EntityReference(“{Entity Name}”, sharingRecordId),
PrincipalAccess = new PrincipalAccess()
{
Principal = new EntityReference(objTeam.LogicalName, objTeam.Id),
AccessMask = AccessRights.WriteAccess
}
};
// Execute the request.
GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grantRequest);
}
//Unshare a record From Team
private void UnShareRecordFromTeam (IOrganizationService service, Guid sharingRecordId, Entity objTeam)
{
RevokeAccessRequest revokeRequest = new RevokeAccessRequest()
{
Target = new EntityReference(“{Entity Name}”, sharingRecordId),
Revokee =new EntityReference(objTeam.LogicalName, objTeam.Id)
};
// Execute the request.
RevokeAccessResponse revoked = (RevokeAccessResponse)service.Execute(revokeRequest);
}
You can use the same code to Share/Unshare a record to User. You just need to pass User details instead of Team like below
Principal = new EntityReference(“systemuser”, userID)
Hope it helps 🙂
Leave a comment Cancel reply
Stats
- 1,778,205 hits
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Step by Step] Dataverse | Plugins | Using Dependent Assemblies
- [Quick Tip] Power Automate flow | Get current Environment ID
- PCF component import error | Publisher prefix for this control does not match the prefix for the solution
- Associate/Disassociate plugin messages in CRM
- Azure DevOps | How to Query Work Items Across Projects
- Power Automate Cloud Flow | 'Correct to include a valid reference' error
- Power Platform | Enable or Disable 'Managed Environment'
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- [Step by Step] Model Driven App | Grids | Navigate to custom page on row click
I am writing the below code to assign a account record to a team . I am getting an error on the last line “The given key was not present in the dictionary.” .
Could you please tell me where is the problem ?
Guid TeamID = new Guid(“9e4c4497-2811-e111-bcdf-00155d017a04”);
Guid accountID = new Guid(“50345443-8a70-e111-a46f-00155d017a04”);
AssignRequest assignRequest = new AssignRequest()
{
Assignee = new EntityReference
{
LogicalName = “team”,
Id = TeamID
},
Target = new EntityReference(“account”, accountID)
};
service.Execute(assignRequest);