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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Check Access button on Command Bar

(0) ShareShare
ReportReport
Posted on by 15

Can we turn off the Check Access button on the command bar through a security role for some of our users or for all users through a System Setting.  It is not a feature we need to display for our users.

I have the same question (0)
  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi AmyWhittemore,

    Below code solve your problem. For more details read my blog on it.

    // A namespace defined for the sample code
    // As a best practice, you should always define
    // a unique namespace for your libraries
    var Person = window.Person || {};
    (function () {
    "use strict"
    var userSettings = Xrm.Utility.getGlobalContext().userSettings;

    this.enableCheckAccess = function (_primaryControl) {
    var isEnableFormConfirm = false;
    try {

    if (CheckSpecificRoleWithAUser(userSettings.userId, "System Administrator")) {
    isEnableFormConfirm = true;
    } else {
    isEnableFormConfirm = false;
    }
    } catch (e) {
    this.openAlertDialog("Error from EnableFormConfirm: " + e.message);
    }
    return isEnableFormConfirm;
    }

    this.checkSpecificRoleWithAUser = function (_systemUserID, _roleName) {
    var userHasRole = false;
    try {
    var fetchData = {
    systemuserid: _systemUserID,
    name: _roleName
    };
    var fetchXml = [
    "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>",
    " <entity name='systemuser'>",
    " <attribute name='fullname' />",
    " <attribute name='systemuserid' />",
    " <order attribute='fullname' descending='false' />",
    " <filter type='and'>",
    " <condition attribute='systemuserid' operator='eq' value='", fetchData.systemuserid, "'/>",
    " </filter>",
    " <link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>",
    " <link-entity name='role' from='roleid' to='roleid' alias='aa'>",
    " <filter type='and'>",
    " <condition attribute='name' operator='eq' value='", fetchData.name, "'/>",
    " </filter>",
    " </link-entity>",
    " </link-entity>",
    " </entity>",
    "</fetch>",
    ].join("");
    this.retrieve(globalVariables.WebAPIVersion, "systemusers", fetchXml);
    if (globalVariables.Results.length > 0) {
    userHasRole = true;
    }
    } catch (e) {
    this.openAlertDialog("Error from CheckSpecificRoleWithAUser: " + e.message);
    }
    return userHasRole;
    };

    this.retrieve = function (webAPIVersion, entitysPluralName, fetchXmlQuery) {
    try {
    var req = new XMLHttpRequest();
    req.open(
    "GET",
    Xrm.Page.context.getClientUrl() +
    "/api/data/" + webAPIVersion + "/" + entitysPluralName + "?fetchXml=" +
    encodeURIComponent(fetchXmlQuery),
    false
    );//Sync
    req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
    req.onreadystatechange = function () {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var results = JSON.parse(this.response);
    globalVariables.Results = results.value;
    } else {
    alert(this.statusText);
    }
    }
    };
    req.send();
    } catch (e) {
    this.openAlertDialog("Error from Retrieve: " + e.message + ".");
    }
    }

    this.openAlertDialog = function (_text) {
    try {
    Xrm.Navigation.openAlertDialog(_text);
    } catch (e) {
    this.openAlertDialog("Error in openAlertDialog: " + e.message + ".");
    }
    }
    }).call(Person);

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans