locked
HELP with a Java Script for Hiding/Showing a Tab based on selection in a look up field RRS feed

  • Question

  • Could you please help me in correcting this JS if it has any mistakes ... It gives me an error... thanks for any help you can give...I am really a beginner. I put it ON LOAD on the form, and ON CHANGE on the look up field. It works when I create and save a new opportunity. But if I try displaying the already existing opportunities, it gives an error on load.

    I need that the tab called: CABLE OPPORTUNITIES - SPECIFIC FIELDS is hidden when the customergroupid field contains an option from P0 to P8. The function I entered is this one


    function HideShowCableTab()
    {
    if (Xrm.Page.getAttribute("scapa_customergroupid").getValue()!=null && (Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P0"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P1"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P2"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P3"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P4"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P5"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P6"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P7"
    || Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P8"))
    {
    Xrm.Page.ui.tabs.get("CABLE OPPORTUNITIES - SPECIFIC FIELDS").setVisible(true);
    }
    else
    {
    Xrm.Page.ui.tabs.get("CABLE OPPORTUNITIES - SPECIFIC FIELDS").setVisible(false);
    }
    }

    Monday, April 14, 2014 10:40 AM

All replies

  • Hi Silvia,
    Are you using the Tab name or label? It appears you are using the label instead of the tab name.

    Monday, April 14, 2014 11:44 AM
  • You may want to try splitting that 'if' statement. If it is NULL (which it will be on a new form), it's still going to try and look at the name element of it which is going to cause problems. Something like this should solve it:

    if (Xrm.Page.getAttribute("scapa_customergroupid").getValue()!=null) { if (Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P0"|| Xrm.Page.getAttribute("scapa_customergroupid").getValue()[0].name == "P1".....)
    {
    Xrm.Page.ui.tabs.get("CABLE OP.......
    }
    else
    {
    Xrm.Page.ui.tabs.get("CABLE OP.......
    }
    }


    • Proposed as answer by Jon_Evans Monday, April 14, 2014 11:45 AM
    Monday, April 14, 2014 11:45 AM