Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Hide/Show Ribbon Workbench button

Posted on by 62

Hi,

I want to check whether a record exists in crm365 and based on that hide/show my Ribbon Workbench Button using javascript. 

What would be the best way to achieve this?

Thanks,

Shreya k

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Hide/Show Ribbon Workbench button

    Hi Shreya,

    As per my information there is no any other way apart from synchronous mode.

  • Shreya kamble Profile Picture
    Shreya kamble 62 on at
    RE: Hide/Show Ribbon Workbench button

    Hi Pravin,

    Thanks for your reply!

    I have used the same code it does resolve the issue.

    But, since the request is snychronous it is having an impact on the performance.

    Regards,

    Shreya K.

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Hide/Show Ribbon Workbench button

    Hi Shreya,

    Please refer below code:

    var UserId = "3AB92M5-H357-E911-A817-00FD3A0B39K8"; // Your user id here

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/roles?fetchXml=%3Cfetch%20version%3D%221.0%22%20output-format%3D%22xml-platform%22%20mapping%3D%22logical%22%20distinct%3D%22true%22%3E%3Centity%20name%3D%22role%22%3E%3Cattribute%20name%3D%22name%22%20%2F%3E%3Cattribute%20name%3D%22businessunitid%22%20%2F%3E%3Cattribute%20name%3D%22roleid%22%20%2F%3E%3Corder%20attribute%3D%22name%22%20descending%3D%22false%22%20%2F%3E%3Clink-entity%20name%3D%22systemuserroles%22%20from%3D%22roleid%22%20to%3D%22roleid%22%20visible%3D%22false%22%20intersect%3D%22true%22%3E%3Clink-entity%20name%3D%22systemuser%22%20from%3D%22systemuserid%22%20to%3D%22systemuserid%22%20alias%3D%22ab%22%3E%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22systemuserid%22%20operator%3D%22eq%22%20uitype%3D%22systemuser%22%20value%3D%22%7BA" + + "%7D%22%20%2F%3E%3C%2Ffilter%3E%3C%2Flink-entity%3E%3C%2Flink-entity%3E%3C%2Fentity%3E%3C%2Ffetch%3E", false);

    //Make sure that you have created request in synchronous mode

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

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

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

    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);

    if(results.value.length > 0)

    return true;

    else

    return false;

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

  • Suggested answer
    Ammar Zaied Profile Picture
    Ammar Zaied 1,670 on at
    RE: Hide/Show Ribbon Workbench button

    Hi Shreya,

    please check links:

    Enable/Disable a ribbon button dynamically based on a form value

  • Shreya kamble Profile Picture
    Shreya kamble 62 on at
    RE: Hide/Show Ribbon Workbench button

    @Pravin Thanks for your reply. I want to return boolean value in order to enable my button based on the retrieved result. Currently, I am using async function to do the same due to which I am unable to return a value. Could you please share some suitable code to achieve this?

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Hide/Show Ribbon Workbench button

    HI Shreya,

    Please refer my below thread for your reference:

    community.dynamics.com/.../942972

    Here I would suggest you to retrieve user roles and hide buttons using enable rule

  • Shreya kamble Profile Picture
    Shreya kamble 62 on at
    RE: Hide/Show Ribbon Workbench button

    I will describe my query more clearly, I have 2 ribbon buttons Assign and Remove on the user form. If a user has been assigned a license, I want to hide the Assign button and show the Remove button and vice versa.

    Thanks,

    Shreya K

  • Suggested answer
    Jagannath Profile Picture
    Jagannath 545 on at
    RE: Hide/Show Ribbon Workbench button

    Hi Shreya,

    As per my understanding , you need to hide the ribbon button for existing record.

    Take this below as a reference.  

    balugajjala.wordpress.com/.../form-state-rulehiding-a-button-when-form-is-in-create-mode-using-ribbon-work-bench-mscrm-2016

    Thanks,

    Jagannath

  • Suggested answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Hide/Show Ribbon Workbench button

    Please check following community post community.dynamics.com/.../253850

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans