You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!


Update Priority based on a Custom Field


This script is used as a post function to change the priority of an issue based on a single-select field.


As a product manager, I have many issues with a single-select custom field called 'affects'. This custom field has many options. I want to assign a priority to the issue depending on the select value.

Good to know

  • This post function should be the first function in your transition, not the last!


  • Jira Jira (8.0 - 8.14)
  • ScriptRunner for Jira ScriptRunner for Jira (6.18.0)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.config.PriorityManager import com.atlassian.jira.issue.customfields.option.LazyLoadedOption final customFieldName = "Single Select List" //Get custom field issue with this name def customFieldManager = ComponentAccessor.customFieldManager def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName) assert customField: "Could not find custom field with name $customFieldName" def customFieldVal = issue.getCustomFieldValue(customField) as LazyLoadedOption //Create priorities def priorities = ComponentAccessor.getComponent(PriorityManager).priorities def highestPriority = priorities.findByName("Highest") def highPriority = priorities.findByName("High") assert highestPriority && highPriority: "One ore more selected priorities doesn't exist" //Assign priority depending on the custom field value switch (customFieldVal?.value) { case "Audit (Internal)": issue.setPriorityId( break case "Audit (External)": issue.setPriorityId( break default: log.debug "No need to change the priority" break }
Discovered an issue? Report it here

Suggested for you

Appears in these Collections