#11 Share Records with Permission using Web API
Ram Prakash
5,055
Implementation Process:
Consider when we have Lookup(Contact) available in Account. So when an Account Page gets saved I need to take the Respective Contact and Assign the same with Permissions.
function shareUserOrTeamtoRecord(executionContext) {
var context = executionContext.getFormContext();
var target = {
"contactid": "ACAAB842-21C7-E811-A96F-000D3A16A41E", // Pass your respective Record id
"@odata.type": "Microsoft.Dynamics.CRM.contact" // Pass your respective Entity Logical name record type
};
// Sharing with Team
var principalAccess = {
"Principal": {
"teamid": "d272654b-57f5-4564-8d0b-36d0d4c426c4",
"@odata.type": "Microsoft.Dynamics.CRM.team"
},
"AccessMask": "ReadAccess, WriteAccess"
//Access Mask Sample "ReadAccess, WriteAccess, AppendAccess, AppendToAccess, CreateAccess, DeleteAccess, ShareAccess, AssignAccess"
};
// Sharing with User
var principalAccess = {
"Principal": {
"teamid": "d272654b-57f5-4564-8d0b-36d0d4c426c4",
"@odata.type": "Microsoft.Dynamics.CRM.team"
},
"AccessMask": "ReadAccess, WriteAccess"
//Access Mask Sample "ReadAccess, WriteAccess, AppendAccess, AppendToAccess, CreateAccess, DeleteAccess, ShareAccess, AssignAccess"
};
var parameters = {
"Target": target,
"PrincipalAccess": principalAccess
};
var req = new XMLHttpRequest();
req.open("POST", context.getClientUrl() + "/api/data/v9.0/GrantAccess", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
var errorText = this.responseText;
//error response
}
}
};
req.send(JSON.stringify(parameters));
}
Thats it 🙂
*This post is locked for comments