web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

getUserPrivilege at the record level?

(0) ShareShare
ReportReport
Posted on by 162

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

I have the same question (0)
  • Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Hello Ning Zhu,

    Please refer below article for your requirement.

    xrmdynamicscrm.wordpress.com/.../

    Thank you,

    Amit Katariya

  • Verified answer
    Community Member Profile Picture
    on at

    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:

    Snipaste_5F00_2022_2D00_03_2D00_24_5F00_13_2D00_14_2D00_43.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 71 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 54 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans