Field-Level Permissions

We've made it easy for you to specify field permissions. In the example below, we show you how to make a field mandatory if the priority field is set to High or Highest. We also have an example on the Behaviours Tutorial page that shows you how to make a field read-only unless a user is in a specific role.

Make a field mandatory if the priority field is a set value 

This example shows you how to make a field mandatory if the priority field is a set value. 

Behaviours only function on the Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens (see Behaviour Limitations). In the example below, we're adding a server-side script to a field, meaning the behaviour will run every time the field is updated.

Scenario

To manage their high-priority issues more effectively, Great Adventure wants the Justification field to be mandatory if the priority is set to High or Highest

If you want to test this example, add a Text Field (multi-line) custom field named Justification.

  1. From ScriptRunner, navigate to Behaviours
  2. Select Create Behaviour.
  3. Enter a name for the behaviour. In this case we enter Make Justification mandatory when high priority.
  4. Optional: Enter a description for the behaviour.
  5. Select Create Mapping.
  6. Then select the project and issue type(s) to map this behaviour to. In this case we chose the Great Adventure VTD project and All issue types.
  7. Select Add Mapping to confirm the mapping.
  8. Select Create to create the behaviour.
     
    You're taken to the Edit Behaviour screen where you can configure the behaviour further.

  9. Scroll to the Add Field field, select the Priority field, and then select Add.
    We now need to add a server-side script to the field for it to show the additional text field when someone selects High or Highest.
  10. Select Create Script.

  11. Copy/paste the following code into the the inline script editor:

    groovy
    import com.atlassian.jira.issue.priority.Priority def priorityField = getFieldById("priority") def justificationField = getFieldByName("Justification") if (((Priority) priorityField.value).name in ["High", "Highest"]) { justificationField.setRequired(true) justificationField.setHelpText("Please explain why this issue is the priority you selected.") } else { justificationField.setRequired(false) justificationField.setHelpText("") }
  12. Select Save Changes

    You can now test to see if this behaviour works!


Related content

On this page