Using a Server-side Validator to set the Fix Versions Required
On this page, we provide you with an example of how to set the Fix Version/s field as required using a server-side script in a Behaviour. For example, when you mark an issue as Resolved with the resolution of Fixed, you want the developer to specify the Fix Version/s. You may also want to hide this field if the resolution is any other resolution, such as Won’t Fix.
Prerequisites
The following example will only work if your project has the following:
- A workflow status with a Resolved status and Resolve Issue transition (or something similar)
- A Resolve Issue transition with a screen associated with it.
- A Resolve Issue transition screen that includes the Resolution and Fix Version/s fields.
- A Resolution field value of Fixed.
- From ScriptRunner, navigate to Behaviours.
- Select Create Behaviour.
- Enter a name for the behaviour. In this example we enter
Set Fix Version as Required
. - Optional: Enter a description for the behaviour.
- Select Create Mapping.
- Select the project and issue type(s) to map this behaviour to. In this example we chose the ITSM project and All issue types.
- Select Add Mapping to confirm the mapping.
- Select Create to create the behaviour.
You're taken to the Edit Behaviour screen where you can configure the behaviour further.
- Scroll to the Add Field field, select the Resolution field, and then select Add.
- Select Create Script. A code editor displays.
Enter the following script:
import com.atlassian.jira.issue.resolution.Resolution def resolutionField = getFieldById("resolution") def fixVersionsField = getFieldById("fixVersions") def resolution = resolutionField.getValue() as Resolution if (resolution.name == "Fixed") { fixVersionsField.setRequired(true) fixVersionsField.setHidden(false) } else { fixVersionsField.setRequired(false) fixVersionsField.setHidden(true) }
This sets the Fix Version/s field to required and shown if the resolution is Fixed, and to optional and hidden if the resolution is anything else.
- Select Save Changes.
You can test to see if this behaviour works. The Fix Version/s field will display as required when the resolution of Fixed is selected. The field will also display a warning if a user tries to transition the issue without adding the fix version.
The Fix Version/s field will disappear if any other resolutions are selected.