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 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
I have the same question (0)
  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at

    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.

  • HelenGar Profile Picture
    15 on at

    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

    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.

  • Suggested answer
    HelenGar Profile Picture
    15 on at

    Thank you so much for your help - that worked perfectly

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at

    Hi,

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

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 46 Most Valuable Professional

#2
Pallavi Phade Profile Picture

Pallavi Phade 33

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 28 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans