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)

Show / Hide tabs javascript

(0) ShareShare
ReportReport
Posted on by 187

I know this has been discussed before so I have attempted to do this using code I found online however the code seems to be broken and not working.

I'd like to hide a Tab on the Project form if Engagement Type is either Fundraising, Buy Side Advisory or Consulting; else show the tab. This is what I've got, any help appreciated:

function showHideProjectTabs()
{
engagementType = Xrm.Page.getAttribute(“new_engagementtypelookup”);
if (typeof (engagementType) != “undefined” && engagementType.getValue() != null)
{
if(engagementType.getText()==”Buy side advisory”)
{
Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(false);
}
else if (engagementType.getText()==”Financial due diligence”)
{
Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(false);
}
else if (engagementType.getText()==”Consulting”)
{
Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(false);
}
}
}

*This post is locked for comments

I have the same question (0)
  • Chickyd Profile Picture
    187 on at
    RE: Show / Hide tabs javascript

    Any chance you could assist in tweaking this code for a field which I want to say if blank hide tab (or the reverse)?

    Current code I have working for the option set is below I'd like to tweak:

    function showPotentialPurchasers() {

    var engagementType = Xrm.Page.getAttribute("new_engagementtypelookup").getValue();

    var sellSideAdvisoryValue = 100000000;

    var fundraisingValue = 100000002;

    if(engagementType != sellSideAdvisoryValue && engagementType != fundraisingValue)

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

    else

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

    }

  • Chickyd Profile Picture
    187 on at
    RE: Show / Hide tabs javascript

    This is amazing, thank you!

    So I now have no errors, but the tab isn't being hidden. I wonder if it's because the code looks like it's saying if all three states are correct rather than if any of them are correct - ie shouldn't it be OR rather than && in the section

    if(engagementType != buySideAdvisoryValue && engagementType != financialDueDiligenceValue && engagementType != consultingValue)

    Thanks!

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Show / Hide tabs javascript

    Hi partner,

    Because there is some error in your code, the system cannot properly read your JS method.

    1. You should change all the double quotation marks to half - corners.

    2. To define a number in JS, you simply type in the full number without adding a separator.

    The below picture shows your previous and modified code.

    community76.png

    Hope it helps.

    Best Regards,

    Leo

  • Chickyd Profile Picture
    187 on at
    RE: Show / Hide tabs javascript

    This is great, thank you.

    So  my code looks like this as you suggest:

    function showPotentialPurchasers() {

    var engagementType = Xrm.Page.getAttribute(“new_engagementtypelookup”).getValue();

    var buySideAdvisoryValue = 100,000,001;

    var financialDueDiligenceValue = 100,000,004;

    var consultingValue = 100,000,003;

    if(engagementType != buySideAdvisoryValue && engagementType != financialDueDiligenceValue && engagementType != consultingValue)

    Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(false);

    Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(true);

    }

    ...but I'm geting the error

    Web resource method does not exist

    Any thoughts?

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Show / Hide tabs javascript

    Hi partner,

    Please check your code format and integrity like missing "}" or ")".

    Then open F12 developer tools when onloading the form and check if the js code has been updated to the latest one. If not, just clear the caches and cookies in your browser and  try again.

    BTW, I suggest that you could use "formContext" instead of "Xrm.page" because this may cause some issues in unified interface.

    You could refer to the following code.

    function getfield(executionContext){

        var formcontext=executionContext.getFormContext();

        var field=formcontext.getAttribute("new_field");

        var value=field.getValue();

        field.setValue("value");

    }

    Hope it helps.

    Best Regards,

    Leo

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Show / Hide tabs javascript

    Hi,

    1) This can be done within the Form Customization. Open Form Editor, select tab, click properties. There you uncheck "Visible by default"

    8547.tab.png

    2) The method wasn't recognized could be due to caching or syntax error in script. Try clearing cache or inprivate/incognito mode. If still it can't reconize, validate your script syntax online https://esprima.org/demo/validate.html. I have seen when we copy paste the code, it change the double quote to some other characters whuch cause script to fail e.g. instead of " changed to ”

    Hope this helps.

  • Chickyd Profile Picture
    187 on at
    RE: Show / Hide tabs javascript

    Thanks, this is really helpful!

    A few questions:

    - I can't see how to set the Tab to be hidden by default - that would be a sensible solution for me. Can you point me to how to do that?

    - When i used the code I pasted above it seemed the function showHideProjectTabs wasn't recognised.  Is this the right start to the code? 

    Forgive my noobness, I'm not that switched on with js and when I did added the code and then rolled it back when it didn't work something else seemed to break so keen to get it right first time next time!

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Show / Hide tabs javascript

    Hello,

    I would suggest following:

    1. instead of the text value, i would use the numeric value. Each optionset besides the text label has also a numeric value associated with it. This gives you the advantage that you can change the label and your code doesn't need any chances to continue working.
    2. I would configure the tab to be hidden by default and set it visible only if the engagement type does not equal consulting, financial due diligence or buy side advisory. This gives a better user experience. Rather than have the tab loaded and disappear in front of the user, the tab is hidden by default and appears if the conditions are true.
    3. You could also simplify the code a bit, for example:
      function showHideProjectTabs() {
      var engagementType = Xrm.Page.getAttribute(“new_engagementtypelookup”).getValue();
      var buySideAdvisoryValue = numeric_value;
      var financialDueDiligenceValue = numeric_value;
      var consultingValue = numeric_value;

      if(engagementType != buySideAdvisoryValue && engagementType != financialDueDiligenceValue && engagementType != consultingValue)
      Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(false);
      Xrm.Page.ui.tabs.get(“Potential_Purchasers”).setVisible(true);
      }
      Whereby you need to replace the numeric_value with the numeric value corresponding to your optionset

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans