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,579,573 hits
Tweets
- RT @MikeFactorial: Big things are coming to the #CoEStarterKit. So, @ManuelaPichler_ and team are building the tension for the April releas… 2 weeks ago
- New blog post : Boost conversations using GPT in Power Virtual Agent (PVA) rajeevpentyala.com/2023/03/08/pow… 2 weeks ago
- RT @PPDevWeekly: 🔥 Going Live: Power Platform Dev Weekly 155 bit.ly/PPDevWeekly155 This week's cover story by @RajeevPentyala With gre… 2 weeks ago
- RT @caseyburke21: Pipelines is now generally available! Huge congratulations to the team and all who have supported reaching this milestone… 3 weeks ago
- New blog post : Call Dataverse actions directly in power-fx rajeevpentyala.com/2023/03/01/ste… 3 weeks ago
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Experimental Feature] Call Dataverse actions directly in Power Fx
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- God Mode - Level Up - Dynamics 365 Chrome Extension
- [Step by Step] Power Apps | Show pop ups in Canvas App
- Associate/Disassociate plugin messages in CRM
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- C# - SQL - Bulk Insert records from Data Table and CSV
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);