Field Required
While Jira allows you to make fields required, ScriptRunner offers more advanced options that allow you to make fields mandatory under specific conditions. This page describes the different capabilities that ScriptRunner provides, and how to configure them.
Making a field required based on a condition
It's easy to make a field required based on a condition using Behaviours. This condition can be selected using the Add new condition option for the field, or the condition can be customized by adding a server-side script. In the example below we have a custom field called Budget Approval Notes that we want to make sure it's mandatory for members of the Finance team when creating or editing issues.
If you want to follow this example step-by-step, make sure you have a custom field called Budget Approval Notes and a group called Finance Team associated with a project. You can also use custom fields and groups of your choice when following this example.
- From ScriptRunner, navigate to Behaviours.
- Select Create Behaviour.
- Enter a name for the behaviour. In this example we enter
Make Budget Approval Notes Required for Finance Team
. - Enter a description for the behaviour. This field is optional.
- Select Create Mapping.
- Then select the project and issue type(s) to map this behaviour to.
- Select Add Mapping to confirm the mapping.
Select Create to create the behaviour.
You're taken to a screen where you can configure the behaviour further.Optional: Enter a guide workflow.
Scroll to the Add Field section and add the Budget Approval Notes field.
- Edit the Optional/Required field so it displays Required. This makes the field mandatory.
- Select Add new condition to add a condition to the Budget Approval Notes field. This condition will run every time the create/edit form loads and when the value of this field changes.
- Configure the condition as follows:
- Select When for Applicability.
- Select Current user in group for Condition.
- Select Finance team for Project role.
Select Add.
Select Save Changes.
You can test to see if this behaviour works by using the switch user function. The Budget Approval Notes field should display as required when the logged in user is a member of the Finance Team.
Making a field required based on a transition
To make a field required on transition we recommend you use the Field(s) Required validator. When you use this validator, issues in your chosen project will throw an error if you try to transition them without completing the required field(s).
Due to how validators work, the field will not show as required (display an asterisk) until you try to transition the issue without completing the required field(s).
Making a field required using Behaviours API
If you want to have a more complex behaviour to make fields required you construct your own script using formField.setRequired(boolean)
.