[转]Jira ScriptRunner Update Priority based on a Custom Field
作者:互联网
本文转自:https://library.adaptavist.com/entity/update-priority-based-on-a-custom-field
Overview
This script is used as a post function to change the priority of an issue based on a single-select field.
Example
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!
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(highestPriority.id)
break
case "Audit (External)":
issue.setPriorityId(highPriority.id)
break
default:
log.debug "No need to change the priority"
break
}
标签:Jira,based,com,Update,priorities,custom,priority,field,issue 来源: https://www.cnblogs.com/freeliver54/p/16024358.html