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 :
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

    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

    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

    Hi Dinesh Raja,

    Please share your code.

  • DineshRaja Profile Picture
    on at

    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

    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
  • Verified answer
    Anchal Profile Picture
    on at

    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

    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

    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

    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…

Neeraj Kumar – Community Spotlight

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

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans