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
  1. From ScriptRunner, navigate to Behaviours
  2. Select Create Behaviour.
  3. Enter a name for the behaviour. In this example we enter Set Fix Version as Required.
  4. Optional: Enter a description for the behaviour.
  5. Select Create Mapping.
  6. Select the project and issue type(s) to map this behaviour to. In this example we chose the ITSM project and All issue types.
  7. Select Add Mapping to confirm the mapping.
  8. Select Create to create the behaviour.
  9. You're taken to the Edit Behaviour screen where you can configure the behaviour further.

  10. Scroll to the Add Field field, select the Resolution field, and then select Add.
  11. Select Create Script. A code editor displays.
  12. 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. 

  13. 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. 

 



Related content

On this page