Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JIRA-Cloud: Create Listener that will change priority field based on a custom field Edited

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"

1 answer

 

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
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you