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 eventdef issue_key = issue.keydef field = issue.fields // current fieldsdef custom_field = 'customfield_10001' // example, change to your own customfield iddef priority = 'customfield_10002' // same thing as above// issue resultdef pageResult = get("/rest/api/2/issue/${issue_key}").header('Content-Type', 'application/json').asObject(Map)// function to update the issuedef 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 Stringdef priority_value = field[priority] as Stringif (customfield_value == 'Value_1') {// add the actual name of the valuepriority_value = "P1"updateIssue(priority, priority_value, issue_key)}// add more conditions here}
It looks like you're new here. Sign in or register to get started.