I have Jira Cloud and am new to the Scriptrunner and using API, can anyone help me to create a listener that will change the priority field to "P1" based on customer field value.
if cutsomfieldvalue = "value1" then Priority = "P1"
You can try the below code, hope it helps you as the basis for customizing what you need.
// listener should be issue_updated event
def issue_key = issue.key
def field = issue.fields // current fields
def custom_field = 'customfield_10001' // example, change to your own customfield id
def priority = 'customfield_10002' // same thing as above
// issue result
def pageResult = get("/rest/api/2/issue/${issue_key}")
.header('Content-Type', 'application/json')
.asObject(Map)
// function to update the issue
def updateIssue(custom_id, value, key) {
def updater = put("/rest/api/2/issue/${key}")
.queryString('overrideScreenSecurity', Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
(custom_id): value,
]
])
.asString()
}
if (pageResult.status < 300) {
def customfield_value = field[custom_field] as String
def priority_value = field[priority] as String
if (customfield_value == 'Value_1') {
// add the actual name of the value
priority_value = "P1"
updateIssue(priority, priority_value, issue_key)
}
// add more conditions here
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.