Announcements
We have getUserPrivilege at the attribute level as documented formContext.getAttribute(arg).getUserPrivilege()
But we need one at the record level to see whether user can read or write or delete to the record, is there a function for that?
Many Thanks,
Ning
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:
Hello Ning Zhu,
Please refer below article for your requirement.
xrmdynamicscrm.wordpress.com/.../
Thank you,
Amit Katariya
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156