Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update Customfield listened using "ScriptRunner for JIRA"

Juan José Marchal Gómez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
November 25, 2019

Hello,

 

I created a script for update priority using Urgency and Impact. This script works as post function but when I'm using as listened is doing nothing. Any error appears in the code but the priority is not updated automatically.

Could you help me?

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option


// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
def priorityMatrix = [
"Very High - Totally stopped": ["All Plants": "Highest", "More than one plant": "Highest", "Partial or totally production plant / More than one department": "High", "Some users / One department / Individual user": "Medium"],
"High - Stopped": ["All Plants": "Highest", "More than one plant": "Highest", "Partial or totally production plant / More than one department": "High", "Some users / One department / Individual user": "Medium"],
"Medium - Works with major limitation": ["All Plants": "High", "More than one plant": "High", "Partial or totally production plant / More than one department": "Medium", "Some users / One department / Individual user": "Low"],
"Low - Works with limitation": ["All Plants": "Medium", "More than one plant": "Medium", "Partial or totally production plant / More than one department": "Low", "Some users / One department / Individual user": "Low"],
]

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def issue = event.issue as Issue
//def issueKey = "IESD-11905"
//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject(issueKey)

def urgencyField = customFieldManager.getCustomFieldObjectsByName("Urgency")

def impactField = customFieldManager.getCustomFieldObjectsByName("Impact")

def urgency = issue.getCustomFieldValue(urgencyField[0]) as Option

def impact = issue.getCustomFieldValue(impactField[0]) as Option

def priorityName = priorityMatrix[urgency.value][impact.value]

def priority = constantsManager.getPriorities().find {it.name == priorityName.toString()}

def issueInputParameters = new IssueInputParametersImpl()

issueInputParameters.setPriorityId(priority.id)
issueInputParameters.setSkipScreenCheck(true)

issue.setPriorityId(priority.id)

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)


if (validationResult.isValid()) {
issueService.update(user, validationResult)
} else {
log.warn validationResult.errorCollection.errors
}

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Laurie Sciutti
Community Champion
July 10, 2023

Hello ~ since you added the scriptrunner tag, have a look here for an example script:  https://community.atlassian.com/t5/Jira-questions/How-do-I-validate-the-value-of-a-custom-Number-Field/qaq-p/772850  

TAGS
AUG Leaders

Atlassian Community Events