Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

Hiding ribbon button

  • 1.  Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 10, 2019 09:11 AM
    ​Hello Team,

    We are using the Opportunity entity. We have a requirement wherein we would like to hide one of the buttons depending on certain values of fields on the Opportunity form.
    As of now I guess this is only achievable way to do so would be via code.

    We have this functionality running in our production 8.2 environment but as it is using legacy code , the code fails to run post we upgrade to version 9 . we have tested this in one of our sandbox environment.

    I am just looking for help assistance around this . as it is version 9 I know that we have to rewrite the code using the new coding methods.
    Please could anyone guide as to how the code could look like .
    If there is an alternative that anyone can suggest we can work on that as well.

    Thank you.

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------
    CRMUG Summit - Post


  • 2.  RE: Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 10, 2019 09:46 AM
    Hello,
    Can you please provide code you use at the moment and screenshots that show how button's command is configured?

    ------------------------------
    Andrew Butenko
    ------------------------------

    CRMUG Summit - Post


  • 3.  RE: Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 10, 2019 10:39 AM
    ​Hi Andrew,

    Thank you for your reply
    .
    Unfortunately I or anyone I know in the team currently does not have complete information as to how this functionality had been achieved :-( . What I can say is the same piece of code or setup works on our PROD environment which is at 8.2 version.

    So we have the button "Close as Won" for Opportunity and the fields in play are "Opportunity Type" and "Income Type", These are option set fields.
    Also we have two more fields which are look up to users . These are panel approvers.

    so we have written a separate JavaScript file named as publisher_MarkasWon


    function EnableCloseAsWon() {

    var result = false;

    try {

    var probability = window.Xrm.Page.getAttribute("pub_probability").getValue();

    if (probability >= 3) {

    if ((window.Xrm.Page.getAttribute("estimatedvalue").getValue() < 0) && window.Xrm.Page.getAttribute("pub_opportunitytype").getValue() == 4)

    result = true;

    else {

    if ((window.Xrm.Page.getAttribute("pub_incometype").getValue() >= 2 && window.Xrm.Page.getAttribute("pub_incometype").getValue() <= 4)) {

    if (window.Xrm.Page.ui.tabs.get("tab_Non-Standard_Brokerage").getVisible() == true) {

    if ((window.Xrm.Page.getAttribute("pub_estimatedstandardbrokerage").getValue()) > (window.Xrm.Page.getAttribute("estimatedvalue").getValue())) {

    if (Xrm.Page.getControl("pub_approvalpanel1").getVisible() == true && Xrm.Page.getControl("pub_approvalpanel2").getVisible() == true) {

    if (window.Xrm.Page.getAttribute("pub_approvalpanel1").getSelectedOption().text == "Approved" && window.Xrm.Page.getAttribute("pub_approvalpanel2").getSelectedOption().text == "Approved") {

    result = true;

    } else {

    result = false;

    }

    }

    else {

    if (Xrm.Page.getControl("pub_approvalpanel1").getVisible() == true) {

    if (window.Xrm.Page.getAttribute("pub_approvalpanel1").getSelectedOption().text == "Approved") {

    result = true;

    }

    }

    if (Xrm.Page.getControl("pub_approvalpanel2").getVisible() == true) {

    if (window.Xrm.Page.getAttribute("pub_approvalpanel2").getSelectedOption().text == "Approved") {

    result = true;

    }

    }

    }

    } else {

    result = true;

    }

    }

    }

    else {

    result = true;

    }

    }

    }

    return result;

    }

    catch (e) {

    if (window.console)

    { console.log(e); }

    }

    }


    What i did get confiused is by the way this is working in Prod .. so this functionality is working in prod and we are not able to make a way as to how this javascripts is even being called..  :-( . we do not even have ribbon workbench installed .. or any cuxtomizations done through it,

    the close as won button
    close as won
    Please let me know if there is any other information i can provide.

    Again Many thanks for your help

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 4.  RE: Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 11, 2019 10:41 AM
    ​Hello Andrew,

    Just checking if you were able to get any information from the code.

    If you could help me with just some sample code or just a way in which I can hide a ribbon through JavaScript or any other method depending on certain field value changes it would be great.

    Thank you.

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 5.  RE: Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 11, 2019 11:29 AM
    Your code looks almost ok for me. Almost because usually window is not used with Xrm. Try to replace window references from your code.
    Regarding code examples how to hide field based on some field value you can use following example - https://balugajjala.wordpress.com/2017/01/27/enabledisable-a-ribbon-button-dynamically-based-on-a-form-value/

    ------------------------------
    Andrew Butenko
    ------------------------------

    CRMUG Summit - Post


  • 6.  RE: Hiding ribbon button

    GOLD CONTRIBUTOR
    Posted Jan 11, 2019 11:35 AM
    ​Hello Andrew,

    Thank you for your reply.
    I will work on this one . Will reach out to you if I need further help

    ------------------------------
    Bhartendu Pandey
    Willis Towers Watson
    London
    ------------------------------

    CRMUG Summit - Post


  • 7.  RE: Hiding ribbon button

    TOP CONTRIBUTOR
    Posted Jan 10, 2019 09:52 AM
    Edited by Rex Kenley Tan Jan 10, 2019 11:03 AM



    Important changes (deprecations) coming in Dynamics 365 Customer Engagement
    Microsoft remove preview
    Important changes (deprecations) coming in Dynamics 365 Customer Engagement
    The announcements and deprecations described in this topic apply to Dynamics 365 Customer Engagement as of version 9. This article was first published on June 27, 2017. Administrators and IT professionals should use this information to prepare for future releases of Dynamics 365.
    View this on Microsoft >


    ------------------------------
    Rex Kenley Tan, MCP
    Tallmadge OH
    https://www.youracclaim.com/users/rex-kenley-tan

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.
    ------------------------------

    CRMUG Summit - Post


If you've found this thread useful, dive deeper into User Group community content by role