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
.
- From ScriptRunner, navigate to Behaviours.
- Select Create Behaviour.
- Enter a name for the behaviour. In this case we enter
Make Justification mandatory when high priority
. - Optional: Enter a description for the behaviour.
- Select Create Mapping.
- 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.
- 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 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. Select Create Script.
Copy/paste the following code into the the inline script editor:
groovyimport 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("") }
Select Save Changes.
You can now test to see if this behaviour works!