[转]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
}

 

 

 

 

posted on 2022-03-19 07:31  freeliver54  阅读(87)  评论(0编辑  收藏  举报

导航