Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Hide/show tab based on form type (create/update)

Posted on by 87

I am trying to use JavaScript, which is definately not my expertisie, to hide/show a tab on a form based on the form type of record. 

If form type is 1 (create) I want to hide the summary tab. If the form type is 2 (update), I want to show the summary tab. 

I have Googled me to the code below, which I use on load of the form - and that works to some extent. 

//Hide Summary tab on Create form 
function HideSummaryTab(executionContext) {   
  //Get form context   
  var formContext = executionContext.getFormContext();   
  //Get form type   
  var formType = formContext.ui.getFormType();   
  //If formtype is Create, hide Summary tab on form     
  if (formType == 1) {
    formContext.ui.tabs.get("summary").setVisible(false);   
  }   
  //To see the form type return value in your browser console
  console.log("Form type = "   formType); 
}

However:

1. Is there any way to avoid the delay there is when the form is loaded? First it loads the form - then it hides the tab. Not the best user experience. 

2. What is the best way to show the tab after save? Do I need to modify the code above, and add an on save event? 

  • Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Hide/show tab based on form type (create/update)

    HI,

    Yes, we need to change the setVisibilty true. later i updated the same code.

    Thanks.

  • NielsSL Profile Picture
    NielsSL 87 on at
    RE: Hide/show tab based on form type (create/update)

    Thanks for your reply, Pradeep Rai 

    In your code, i just need to change setVisbility to true :)

    I played a bit around with this, and I came to the conclusion, that using setFocus works better for my use case. 

  • Verified answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Hide/show tab based on form type (create/update)

    HI,

    Code looks good. 

    I have below suggestion for above need:

    1. By default keep the tab visibility to hide using below property. So, on create(formType==1) the tab will be hidden. 
    pastedimage1635784335575v1.png

    2. When user update the record (formType==2) then use below JavaScript to show the tab.

    //Hide Summary tab on Create form 
    function HideSummaryTab(executionContext) {   
      //Get form context   
      var formContext = executionContext.getFormContext();   
      //Get form type   
      var formType = formContext.ui.getFormType();   
      //If formtype is Create, hide Summary tab on form     
      if (formType == 2) {
        formContext.ui.tabs.get("summary").setVisible(true);   
      }   
    
    }



    With above approach user will consistent experience. 

    Thanks,
    Pradeep.

    Please mark this as VERIFIED. if it helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans