Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

getUserPrivilege at the record level?

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    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:

    Snipaste_5F00_2022_2D00_03_2D00_24_5F00_13_2D00_14_2D00_43.png

  • Amit Katariya007 Profile Picture
    Amit Katariya007 6,407 Moderator on at
    RE: getUserPrivilege at the record level?

    Hello Ning Zhu,

    Please refer below article for your requirement.

    xrmdynamicscrm.wordpress.com/.../

    Thank you,

    Amit Katariya

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans