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
}
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
here are additional examples: https://docs.adaptavist.com/sr4js/latest/features/workflows/validators/built-in-validators/simple-scripted-validators
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.