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

Priority Change ScriptRunner Listener

Philipp Hartl February 22, 2023

Hello,

im currently trying to set up a listener to receive notification when priority is changed. Request is that the original prio is defined (P3) and new prio is P2. Thus notifications should only be received when Prio3--> Prio2 but not for Prio3-->Prio1 or Prio1-->Prio3

I tried to config this with template from listener and add something but i dont receive any notification:

 

Condition and Configuration Option1:

originalIssue.priority == 'Medium (P3)'
issue.priority?.name == 'High (P2)' && issue.priority != originalIssue.priority
Condition and Configuration Option2:
issue.priority?.name == 'High (P2)' && originalIssue.priority == 'Medium (P3)'&& changeItems.any {
    it.get('field')=='priority'
}
Could you please help me out here?
Thank you!

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
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 Leaders.
February 22, 2023

You could try it like this:

if(originalIssue.priority.name != 'Medium (P3)') return false
if(issue.priority?.name != 'High (P2)') return false
true

By default if the current priority is different than the original priority, that means the priority was changed in the event. So there is no need to also look in the changeItems

 

Philipp Hartl February 23, 2023

Hello Peter-Dave,

thanks for your help!

Unfortunately i am not receiving any notifications. Do i need to add something to your code snippet?

Peter-Dave Sheehan
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 Leaders.
February 23, 2023

Add some logs and review the details after the execution:

log.info "Original Priority=$originalIssue.priority.name"
if
(originalIssue.priority.name != 'Medium (P3)') {
log.info "Condition is false because original priority was not 'Medium (P3)'"
return false
}
log.info "Current priority=$issue.priority.name"
if
(issue.priority?.name != 'High (P2)') {
log.info "Condition is false because current priority is not 'High (P2)'"
return false
}
log.info "Returning true"
true
Philipp Hartl February 24, 2023

This is what i receive when i switch from P3 to P2:

2023-02-25 00:49:23,017 INFO [runner.ScriptBindingsManager]: Original Priority=High (P2)

2023-02-25 00:49:23,017 INFO [runner.ScriptBindingsManager]: Condition is false because original priority was not 'Medium (P3)'

 

And if my current priority is P4 or anything else and i switch to P3 i get this:

2023-02-25 00:48:45,972 INFO [runner.ScriptBindingsManager]: Original Priority=Medium (P3)

2023-02-25 00:48:45,973 INFO [runner.ScriptBindingsManager]: Current priority=Medium (P3)

2023-02-25 00:48:45,973 INFO [runner.ScriptBindingsManager]: Condition is false because current priority is not 'High (P2)'

Peter-Dave Sheehan
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 Leaders.
February 28, 2023

Sorry, I missed the notification.

I investigated this a bit and it turns out that the "originalIssue" object provided in the Send Email condition doesn't work as you'd expect in this context.

That only works in workflow postfunctions I believe.

For listeners, you have to get the details of the old values from the changelog.

Try this:

import com.atlassian.jira.component.ComponentAccessor

def changeLog = event.changeLog
if (!changeLog) {
log.info "Condition is false because the event doesn't contain a changeLog"
return
}

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def changeItemBeans = changeHistoryManager.getChangeHistoryById(changeLog.id as Long).changeItemBeans

def priorityChangeItem = changeItemBeans.find { it.field == 'priority' }
if (!priorityChangeItem) {
log.info "Condition is false because priority field was not found in the changeLog"
return
}

log.info "Priority change detected from $priorityChangeItem.fromString to $priorityChangeItem.toString"
if (priorityChangeItem.fromString != 'Medium (P3)') {
log.info "Condition is false because original priority was not 'Medium (P3)'"
return false
}

if (priorityChangeItem.toString != 'High (P2)') {
log.info "Condition is false because current priority is not 'High (P2)'"
return false
}
log.info "Returning true"
true
Like Philipp Hartl likes this
Philipp Hartl March 1, 2023

Hello,

thanks for your reply. I tested it and i finally receive a mail. Thank you very much for your help!

 

I get these 2 logs:

2023-02-28 22:34:52,657 INFO [runner.ScriptBindingsManager]: Priority change detected from High (P2) to Medium (P3) 2023-02-28 22:34:52,658 INFO [runner.ScriptBindingsManager]: Condition is false because original priority was not 'Medium (P3)'

2023-02-28 22:34:57,836 INFO [runner.ScriptBindingsManager]: Priority change detected from Medium (P3) to High (P2) 2023-02-28 22:34:57,837 INFO [runner.ScriptBindingsManager]: Returning true

Peter-Dave Sheehan
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 Leaders.
May 3, 2023

It would seem that you were able to resolve the issue and get the notifications you expect.

I would appreciate it if you could mark this thread as the accepted answer.

Thanks

0 votes
Philipp Hartl February 22, 2023

Sry i think this question is in the wrong section..

TAGS
AUG Leaders

Atlassian Community Events