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:
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
Hello Peter-Dave,
thanks for your help!
Unfortunately i am not receiving any notifications. Do i need to add something to your code snippet?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.