Operations on Tabs
If your screen has multiple tabs you can use our Behaviours feature to hide, disable, or switch to a tab. By leveraging these functions you can create a more intuitive and controlled user experience.
hideTab()- This function allows you to completely remove a tab from view. It's particularly useful when you want to prevent certain fields from being edited at specific stages of the workflow or by particular groups or roles.
disableTab()- You can choose to disable a tab rather than hide it entirely. This approach keeps the tab visible but inaccessible, indicating to users that the tab exists but is not applicable or forbidden at that moment.
switchTab()- This function allows you to programmatically change the active tab. It's especially valuable when used in conjunction with hiding or disabling tabs, as you can direct users to a specific alternative tab. If you don't specify a target tab when hiding or disabling another, the system will default to the left-most tab that remains visible and active. However, we recommend using this function wisely, as frequent automatic tab switching in response to field changes might confuse users.
Should I add an initialiser or server-side script?
When setting up a behaviour you may want to determine when your behaviour runs:
- If you want the behaviour to run when the Create Issue, Edit Issue, or Transition issue page loads , set up an Initialiser. If you are manipulating tabs based on groups, roles, or stages in the workflow, we recommend you add an initialiser script.
- If you want the behaviour to run every time a user updates the value of a field, we recommend set up a server-side script to react to the user input . The option to add a server-side script appears once you have added a field.
Examples
Below we provide two examples for hiding tabs. The simple example displays the usage of hideTab(), disableTab(), and switchTab() in one script. The step-by-step example walks you through a practical example that you can easily follow.
Simple example
In this example, we have three tabs ( Main, Testing, and Customer). When the current user is a member of a group, such as jira-users, we want to:
- Hide the Main tab
- Disable the Testing tab
- Switch to the Customer tab
We map our behaviour to the IssueWithTabs issue type and use the following code in the Initialiser script editor:
def user = Users.getLoggedInUser()
if
(user.isMemberOfGroup('jira-users')) {
hideTab(0)
disableTab(1)
switchTab(2)
}0, the second as 1, and so on. Alternatively, you can use the tab names directly instead of their indices:
def user = Users.getLoggedInUser()
if (user.isMemberOfGroup('jira-users')) {
hideTab('Main')
disableTab('Testing')
switchTab('Customer')
}This results in the following whenever a member of the jira-users group creates, transitions, or edits an IssueWithTabs issue:
Step-by-step example
In this example, we have three tabs (Field Tab, Priority Tab, and Admin Tab). We want to hide the Admin Tab if a user is not an admin.
You can test to see if this behaviour works by using the switch user function.