We can use RetrievePrincipalAccess function in Web API to get the access rights of either a user or team on a specific record.
The sample code:
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/systemusers(D38F5B76-C22E-4256-AF90-CFD14B6589BF)"+
"/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target =@Target)?"+
"@Target={ 'accountid': '8CB09F67-EB90-E811-A963-000D3AD1CBD6', '@odata.type': 'Microsoft.Dynamics.CRM.account' } ", false);
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 === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
Result:

Hope it helps..
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

In case of JS we need to use the below code on ribbon button to show and hide based on access rights:
function canCurrentUserWrite(primaryControl){if (!primaryControl) return false;var privileges = primaryControl.data.entity._privileges;if (privileges && typeof privileges.canUpdate !== "undefined"){return privileges.canUpdate;}return false;}LikeLike