Archive
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 🙂
Stats
- 1,558,525 hits
Tweets
- RT @ManuelaPichler_: I suffered a concussion last week, and I'm so glad to see this video is actually REAL and not just something my brain… 4 days ago
- RT @TaikiYoshidaEN: Awesome to see we have a shiny new public facing website for Power CAT! 😻😻😻 microsoft.github.io/powercat/ #PowerApps #PowerA… 1 week ago
- RT @ravichada: 🎥 The demo video is ready now. Do check out the Dataverse Security Roles risk assessment tool in action. Leave a comment or… 1 week ago
- RT @ManuelaPichler_: CoE kit but make it more fluent-y #comingsoon https://t.co/kcSzPqwZhM 1 week ago
- New Blog Post: C# Basics | Why Interfaces rajeevpentyala.com/2023/01/07/c-b… 4 weeks ago
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- [Step by Step] Postman tool with Microsoft Dataverse Web API
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- [Step by Step] Model-driven apps | In-app notifications
- Azure DevOps (ADO) | Pipeline failure | You need the Git 'GenericContribute' permission
- Associate/Disassociate plugin messages in CRM
- Power Apps - 'Environment Variables' and their usage in Canvas Apps
- Power Automate Flows | 'Callback Registration Expander' System Jobs stuck at 'Waiting For Resources'