Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

RevokeAccess action not working

Posted on by 20

Hello,

I am developing a dashboard (via javascript) to allow users to grant or revoke access of records to teams. I have had no issue with the GrantAccess action, but I receive an error code:400 when I send a request to RevokeAccess. 

// GrantAccess action parameters - working 

        {
            "Target": {
                "new_employeeid" : employeeid,
                "@odata.type" : "Microsoft.Dynamics.CRM.new_employee"
            },

            "PrincipalAccess": {
                "Principal" : {
                    "teamid" : teamid,
                    "@odata.type" : "Microsoft.Dynamics.CRM.team"
                },
                "AccessMask" : "ReadAccess"
            }
        }

// RevokeAccess action parameters - error

        {
            "Target": {
                "new_employeeid" : employeeid,
                "@odata.type" : "Microsoft.Dynamics.CRM.new_employee"
            },

            "Revokee": {
                "teamid": teamid,
                "@odata.type": "Microsoft.Dynamics.CRM.team"
            }
        }
Your assistance would be greatly appreciated.
Thank you,
Scott
  • Scott Parks Profile Picture
    Scott Parks 20 on at
    RE: RevokeAccess action not working

    Hi Andrew,

    Here is the complete code.  

    var parameters = {

               "Target": {

                   "new_employeeid" : employeeid,

                   "@odata.type" : "Microsoft.Dynamics.CRM.new_employee"

               },

               "PrincipalAccess": {

                   "Principal" : {

                       "teamid" : teamid,

                       "@odata.type" : "Microsoft.Dynamics.CRM.team"

                   },

                   "AccessMask" : "ReadAccess"

               }

           }

           var uri = window.parent.Xrm.Page.context.getClientUrl() + API.strWEBAPIPATH + "/GrantAccess";

           var request = new XMLHttpRequest();

           request.open("POST", encodeURI(uri), true);

           request.setRequestHeader("OData-MaxVersion", "4.0");

           request.setRequestHeader("OData-Version", "4.0");

           request.setRequestHeader("Accept", "application/json");

           request.setRequestHeader("Content-Type", "application/json; charset=utf-8");

           request.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");

           let ready = true;

           request.onreadystatechange = function () {

               if (this.readyState === 4) {

                   request.onreadystatechange = null;

                   if (this.status === 200) {

                       debugger;

                       // success - do something

                   }

                   if(this.status === 204) {

                       debugger;

                       // success - do something

                   }

                   else {

                       ready = false;

                   }

               }

               else {

                   ready = false;

               }

           };

           if (ready) request.send(JSON.stringify(parameters));

    When I send a request with "/GrantAccess" appended to the end of the URI everything works as expected and the team gets access to the employee, however when I append "/RevokeAccess" I receive an error that there is no HTTP resource matching the request URI.

    Thank you,

    Scott

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: RevokeAccess action not working

    Hello Scott,

    I believe that's not the whole code. Can you please provide the full version starting from the part where you define the request and ending where you call the api?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans