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 (Archive)
Answered

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

(0) ShareShare
ReportReport
Posted on by 85

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? 

I have the same question (0)
  • Pradeep Rai Profile Picture
    5,490 Moderator 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
    85 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
    5,490 Moderator 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

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard > 🔒Ι Microsoft Dynamics CRM (Archived)

Featured topics

Product updates

Dynamics 365 release plans