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 Reply Cancel reply
Stats
- 1,244,608 hits
Translate
Categories
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Step by Step] Postman tool to test Dynamics 365 online Web API
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- [Step by Step] Debug Model Driven and Canvas Apps using 'Monitor' tool
- [MS Word] The Linked file isn't available
- Sandbox vs Production Instances – Dynamics 365
- Associate/Disassociate plugin messages in CRM
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
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);