Using Scriptrunner with Behaviours to Show/Hide a Multiline Text Field Based on Checkbox Selection
If you’re working with Jira and want to create a dynamic form that shows or hides a multiline text field when a specific checkbox option is selected, Scriptrunner with Behaviours is your go-to solution. In this guide, we’ll walk through how to configure this functionality using a script.
Prerequisites
- Jira with Scriptrunner installed.
- Basic knowledge of Jira custom fields and scripting.
Step-by-Step Guide
- Create the Custom Fields:
- Go to your Jira administration settings and create a Checkbox custom field. Let’s name it
Options. - Add options to this field, including an option named “Others”.
- Create a Multiline Text Field custom field. Let’s name it
Details.
- Go to your Jira administration settings and create a Checkbox custom field. Let’s name it
- Add the Fields to Your Screen:
- Ensure that both the
OptionsandDetailsfields are added to the relevant screens where you want this behaviour to be applied.
- Ensure that both the
- Navigate to Scriptrunner Behaviours:
- Go to the Scriptrunner section in Jira administration.
- Click on “Behaviours” and then “Add Behaviour”.
- Configure the Behaviour:
- Select the appropriate project and issue type for this behaviour.
- Add a mapping for the screen where your fields are located.
- Add a Server-Side Script:
- In the Behaviours configuration, click on the “Options” field.
- Add the following server-side script to handle the show/hide logic:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import static com.atlassian.jira.issue.IssueFieldConstants.*
def optionsField = getFieldByName("Options")
def detailsField = getFieldByName("Details")
def optionsValue = optionsField.getValue() as List
if (optionsValue.contains("Others")) {
detailsField.setHidden(false)
detailsField.setRequired(true)
} else {
detailsField.setHidden(true)
detailsField.setRequired(false)
}
This script does the following:
- Retrieves the
Optionsfield value. - Checks if the “Others” option is selected.
- If “Others” is selected, the
Detailsfield is shown and made required. - If “Others” is not selected, the
Detailsfield is hidden and not required.
- Test Your Configuration:
- Create or edit an issue in the project and issue type where this behaviour is applied.
- Check the
Optionsfield and select “Others”. TheDetailsfield should appear. - Deselect “Others” to see the
Detailsfield disappear.
Conclusion
By using Scriptrunner with Behaviours, you can create dynamic and responsive forms in Jira that enhance user experience and data collection. This guide provided a simple example of showing or hiding a multiline text field based on a checkbox selection. Experiment with other conditions and field types to further customize your Jira workflows!
Feel free to leave a comment below if you have any questions or need further assistance!
Screenshots with similar example:

- You can set Hidden the field as default in the initialiser

- In the field script, in this case “Type of Product”, the imports in the code are not needed

Post by MrAddon by TecnoFor by Sngular
.
#AtlassianCreator #Jira #Scriptrunner #Behaviours #MultilineTextField #Checkbox #CustomFields #JiraAdministration #JiraCustomization #DynamicForms #JiraScripting #WorkflowAutomation #JiraTips #Atlassian #JiraPlugins #IssueTracking





