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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript For Show/Hide Tab

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am using the following code to hide two tabs and show them depending on the value returned form the option set however I continue to get the error below.

4747.script-error.png

And My Coding is In below.

codng.png

How to Resolve the Error.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PS Profile Picture
    23,577 on at
    RE: JavaScript For Show/Hide Tab

    Hi DineshRaja

    Following is a sample code:

    function ShowHideOpp()  {

    {

    var Lead = Xrm.Page.getAttribute("leadsource").getValue();

    var New Hire = Xrm.Page.ui.tabs.get("tab_7");

    var Resale = Xrm.Page.ui.tabs.get("tab_8");

    if (Lead != "1") {

    Xrm.Page.ui.tabs.get("Resale").setVisible(false);

    }

    else if (Lead == "1") {

    Xrm.Page.ui.tabs.get("New Hire").setVisible(false);

    }

    }

    }

    Basically, you have to get the numeric value of option set, do not convert it to text

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at
    RE: JavaScript For Show/Hide Tab

    HI

    In your code you used .text property Xrm.Page.getAttribute('new_accupation') itself null.

    Validate whether it returns control instance or not

    Also dont use option set value to text. Use the number and put condition based on the number.

  • Nithya Gopinath Profile Picture
    17,078 on at
    RE: JavaScript For Show/Hide Tab

    Hi Dinesh Raja,

    Please share your code.

  • DineshRaja Profile Picture
    on at
    RE: JavaScript For Show/Hide Tab

    The Code is below.

    function hideTabSection() {

       var option = Xrm.Page.getAttribute("new_occupation").getSelectedOption().text;

       if (option == "") {

           Xrm.Page.ui.tabs.get(Work).setVisible(false);

           Xrm.Page.ui.tabs.get(Study).setVisible(false);

       }

    else if (option == "Work")

            {

               Xrm.Page.ui.tabs.get(work).setVisible(true);

               Xrm.Page.ui.tabs.get(Study).setVisible(false);

            }

    else if (option == "Study")

       {

           Xrm.Page.ui.tabs.get(Study).setVisible(true);

           Xrm.Page.ui.tabs.get(Work).setVisible(false);

       }

    }

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: JavaScript For Show/Hide Tab

    Use below code:

    function hideTabSection() {

      var option = Xrm.Page.getAttribute("new_occupation").getText();

      if (option == "") {

          Xrm.Page.ui.tabs.get("Work").setVisible(false);

          Xrm.Page.ui.tabs.get("Study").setVisible(false);

      }

    else if (option == "Work")

           {

              Xrm.Page.ui.tabs.get("work").setVisible(true);

              Xrm.Page.ui.tabs.get("Study").setVisible(false);

           }

    else if (option == "Study")

      {

          Xrm.Page.ui.tabs.get("Study").setVisible(true);

          Xrm.Page.ui.tabs.get("Work").setVisible(false);

      }

    }

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: JavaScript For Show/Hide Tab

    See :

    arunpotti.wordpress.com/.../get-optionset-text-and-value-using-javascript

  • Verified answer
    Anchal Profile Picture
    on at
    RE: JavaScript For Show/Hide Tab

    Use this code. You have to give tab name in double quote(" ").   

    var option = Xrm.Page.getAttribute("new_occupation").getSelectedOption().text;

       if (option == "") {

           Xrm.Page.ui.tabs.get("Work").setVisible(false);

           Xrm.Page.ui.tabs.get("Study").setVisible(false);

       }

    else if (option == "Work")

            {

               Xrm.Page.ui.tabs.get("Work").setVisible(true);

               Xrm.Page.ui.tabs.get("Study").setVisible(false);

            }

    else if (option == "Study")

       {

           Xrm.Page.ui.tabs.get("Study").setVisible(true);

           Xrm.Page.ui.tabs.get("Work").setVisible(false);

       }

    }

  • DineshRaja Profile Picture
    on at
    RE: JavaScript For Show/Hide Tab

    Hi Anchal,

                  if (option == "" || option =="null" || option =="undefined") {

         Xrm.Page.ui.tabs.get("Work").setVisible(false);

         Xrm.Page.ui.tabs.get("Study").setVisible(false);

     }

               Am use this if statement but The Work and Study Tabs are Visible in null..after change the option Set value the Tab are hide..how to hide the both tab in null value

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: JavaScript For Show/Hide Tab

    Hi Dinesh Raja,

    Instead of enclosing "null" and "undefined" in quotes, try the code below.

      if (option == "" || option == null || option == undefined) {
         Xrm.Page.ui.tabs.get("Work").setVisible(false);
         Xrm.Page.ui.tabs.get("Study").setVisible(false);
    }
  • DineshRaja Profile Picture
    on at
    RE: JavaScript For Show/Hide Tab

    Thank You

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans