Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Hide/Show Tab depending on field choice

(0) ShareShare
ReportReport
Posted on by 15

I know this has been asked many times before and I have looked through many solutions but I can not get it to work!

Could someone please try and see where I am going wrong

This is the js I am saving as a webresource:

function HideTabs(executionContext){

var formContext = executionContext.getFormContext();

var tabObj = formContext.ui.tabs.get("drca");

if(formContext.getAttribute("lwa_pensionact").getValue()!=null && formContext.getAttribute("lwa_pensionact").getValue()[0].name=="DRCA"){

tabObj.setVisible(false);

}

else{

tabObj.setVisible(true);

}

}

Then I save as resource and add to solution library

pastedimage1681352021651v5.png

Then add to the column event - on change

pastedimage1681351842492v2.png

And add to the form event - onload

pastedimage1681351925743v3.png

If I go back to Edit webresource I noticed the file has changed to this - is that normal?

pastedimage1681351971463v4.png

I am getting the following error

Script Error One of the scripts for this record has caused an error. For more details, download the log file.

Web resource method does not exist: HideTabsSession Id: 5e2bc000-fb8c-4790-940f-4be32cfe6aebCorrelation Id: 0b40047e-2d44-4b5d-990c-c633c598a631Event Name: onloadFunction Name: HideTabsWeb Resource Name: lwa_hidetabs
Any help would be greatly appreciated.
Thanks
  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Hide/Show Tab depending on field choice

    Hi,

    Could you mark my reply as verified to close this post ?

  • Suggested answer
    HelenGar Profile Picture
    15 on at
    RE: Hide/Show Tab depending on field choice

    Thank you so much for your help - that worked perfectly

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Hide/Show Tab depending on field choice

    Hi,

    From the error, it seems that the lwa_pensionact field is not a lookup, but is a choice field (option set) ?

    If it's a choice field, use:

    function HideTabs(executionContext){
        var formContext = executionContext.getFormContext();
        var tabObj = formContext.ui.tabs.get("drca");
        
        // Replace 123 by the option set value for DRA
        if(formContext.getAttribute("lwa_pensionact").getValue() == 123){
            tabObj.setVisible(false);
        }
        else {
            tabObj.setVisible(true);
        }
    }

    Replace 123 by the option set value for DRA.

  • HelenGar Profile Picture
    15 on at
    RE: Hide/Show Tab depending on field choice

    Hi Xavier

    Thank you for your response.

    I am extremely new to javascript. I checked the Pass execution context as first parameter but it still doesn't work.

    Its says Cannot read properties of undefined (reading 'name')

    Any clues?

    Thanks

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at
    RE: Hide/Show Tab depending on field choice

    Hello,

    Your function use the execution context, "Pass execution context as first parameter" must be checked.

    Concerning the name, it's normal. It is the one you have defined for the web-resource. The file name is not used to define the name.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans