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,465,799 hits
Translate
Categories
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- [Step by Step] Using TypeScript in Dynamics 365 9.x
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- Associate/Disassociate plugin messages in CRM
- 'Callback Registration Expander' System Jobs stuck at 'Waiting For Resources'
- Power Apps | Business Rule | Set Field Value vs Set Default Value
- Dynamics Portal - 'No list could be found with the relative URL' Error - Fix
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS