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)

Hide tab based on yes/no option set value in CRM 2013

(0) ShareShare
ReportReport
Posted on by

Hello,

I am attempting to show a tab on a form if a particular field is set to "yes". I created a web resource with the following jscript:

"Puts" is the tab name, "bkdt_fhtc" is the field name and "1" is the value for yes in the option set.

The event handler information looks like this:

I have tried to do this at least 20 different ways and continue to get the following error onload:

I am currently stonewalled and would greatly appreciate any suggestions or alternatives.

Thanks,

Mike

*This post is locked for comments

I have the same question (0)
  • Sindre Wetting Profile Picture
    on at

    You cannot pass string value as attributes in the function, so either remove the funciton arguments so that the function looks like:

    function settabname() { ... }

    or if you want to pass parameters in your you have to use variables in your as your function arguments like this (and make it reusable):

    function settabname (attributename, tabname) {

    Xrm.Page.getAttribute(attributename).getValue();

    }

  • G Sav Profile Picture
    on at

    I use a script similar to below and it is fired on Form open to hide or show a TAB, but I also have it fire

    when the field is updated. So if some changes the field the form changes infront of them.

    function functionname()

    {

               if(Xrm.Page.getAttribute("fieldname").getSelectedOption() != null)

               {

                           var appointmentType = Xrm.Page.getAttribute("fieldname").getSelectedOption().value;

                           //Value 1

                           if(appointmentType == 131090002)

                           {                      

                           Xrm.Page.ui.tabs.get("TAB").setVisible(false); //Hide Tab

                          }

                           //Value 2

                           if(appointmentType == 131090003)

                           {                      

                           Xrm.Page.ui.tabs.get("TAB").setVisible(false); //Hide Tab

                           }                      

               }

    }

  • Suggested answer
    Rasmus R. Aardal Profile Picture
    on at

    Hi Mike,

    In Dynamics CRM 2013, this can be solved using Business Rules.

    To do this, navigate to the form designer and select "Business Rules". Add a new Business Rule with the following condition:

    if Field bkdt_fhtc equals Value Yes

    and the action:

    Hide Field X

    Hide Field Y

    Hide Field Z

    ..and so forth, the fields being those contained in the tab you wish to hide.

    If you have a lot of fields in your tab, setting up the rule can be time consuming. But then again, Business Rules are supported and require no knowledge of JScript to set up. If you need to hide/show the label in addition to the fields, the rule can be supplemented with some JScript.

    Good Luck!

    Regards,

    Rasmus

  • G Sav Profile Picture
    on at

    business rules have the limitation you can only hide/show fields, you can not hide/show tabs.

  • joenewstrom Profile Picture
    6 on at

    You don't need parameters if you're setting the tab statically in your script. Typically you invest the time to make the script repeatable i.e. you could use it on multiple forms with multiple tabs. You'd do this by reforming it like this:

    function toggleTabVisibilityWithBoolean (tab, booleanField) {

      var booleanValue = Xrm.Page.getAttribute(booleanField).getValue(); //get the value of the boolean

      Xrm.Page.ui.tabs.get(tab).setVisible(booleanValue); /*set the visibility of the tab to the value of the boolean (checked means visible, unchecked means hidden)*/

    }

    Then just pass 2 parameters, tab name in "quotes" and boolean name in "quotes". Otherwise if you insist on using static parameters, stick with your function data above, change the function to function showtabnew() and don't pass any parameters at all. But that's not the clean way to do it as you'll need to create a new script webresource for every tab on every page which is a huge waste of time.

    Also, if you have more than one script library on the page, make sure you're choosing the library where your script is stored.

  • Community Member Profile Picture
    on at

    Your the variable names in your function showatabnew do not need to be quoted. I think it should look like this instead:

    function showatabnew(var1, var2, var3)

    {

      ...

    }

  • Community Member Profile Picture
    on at

    I look forward to a business rule expansion that enables us to hide entire Tabs rather than fields.  We run a business with 10 different groups of customers and all have very different fields that need to be completed.  Some of these "hide field" rules run to 20 fields for each group when a simple hide tab would be great.  But yes , this is the best and only real supported way to do this.

  • swava Profile Picture
    on at

    Hi Joe,

    I am getting Error: Unable to get property 'getValue' of undefined or null reference.  Would you know why?

    bit field name = new_hide

    tab name = New

  • Suggested answer
    jccrm Profile Picture
    on at

    All the others haven't really addressed this, so I thought I'd answer it. Documented below with jsDoc and on each line to outline how it's done.

    /**
     * @brief A function that hides a given tab of tab_name if field_name == 1
     * @param {string} field_name The name of the field.
     * @param {string} tab_name The name of the tab.
     */
    function hideTabByFieldValue(field_name, tab_name) {
        
        // Cache first so you know what this function does.
        var my_field = Xrm.Page.getAttribute(field_name);
        
        // Let's not get an error when trying to access field_name if it doesn't exist. 
        if (my_field !== null && my_field.getValue() !== null) {
    
            // Use the get callback method instead.
            var my_tab = Xrm.Page.ui.tabs.get(function (tab_item) {
    
                // Loop the forms using ui.tabs.get callback, and check if it's tab_name && field_name's value is 1
                if (tab_item.getLabel().toLowerCase() == tab_name) {
    
                    // Set the tab item as visible based upon field's value. This way if you use it as a callback 
                    // And it's ticked or unticked, it'll update the visibility.
                    tab_item.setVisible((my_field.getValue() == 1));
                }
            });
        }
    }
    


    Happy hunting, the documentation is your friend. :)

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