RE: getUserPrivilege at the record level?
Hi Ning Zhu,
It seems you want to achieve this by JS. Please try the following code:
function onload(executionContext){
var formContext = executionContext.getFormContext();
var globalContext = Xrm.Utility.getGlobalContext();
//Get client url
var clientUrl = globalContext.getClientUrl();
//Get current user id
var currentUserId = Xrm.Utility.getGlobalContext().userSettings.userId.replace(/{|}/g,'');
//Get current record reference
var currentRecordReference = formContext.data.entity.getEntityReference();
//plural of logical name(Sometime you need add 'es' or remove 'y' then add 'ies')
var logicalName = currentRecordReference.entityType + 's';
var recordId = currentRecordReference.id.replace(/{|}/g,'');
var target = "{'@odata.id':'" + logicalName + "(" + recordId + ")'}";
var url = clientUrl + "/api/data/v9.2/systemusers(" + currentUserId + ")/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@tid)?@tid=" + target;
var request = new XMLHttpRequest();
request.open("get", url , true);
request.setRequestHeader("OData-MaxVersion", "4.0");
request.setRequestHeader("OData-Version", "4.0");
request.setRequestHeader("Accept", "application/json");
request.onreadystatechange = function () {
if (request.readyState === 4) {
console.log(JSON.parse(request.responseText));
}
}
request.send();
}
Result: