We are trying to write a simple Listener that will fire only the once per a certain field is being changed to a set criteria. The Condition works fine, but we are struggling to set it to the right Event; as the Custom email is sent when the condition is met, but also every time an issue with this criteria is updated.
When you use 'cfValues(..)' it will look up the field value each time the listener is triggered, so I assume every time the issue is updated, just guessing that that is the event it listens to.
What you probably are after is verifying that the custom field has actually been changed as part of this event -- i.e., only check if the field has been changed, if so, check the value and do x, if the field is not being changed in this event, do nothing.
Something like this could work:
def changeItem = event.getChangeLog()?.getRelated("ChildChangeItem")?.find {
it.field == "Custom Field Name"
}
if (changeItem != null) {
// field is being changed, we can either read the data from changeItem, or we can re-use the built-in method
if ("Yes".equals(cfValues["Custom Field Name"]?.get(null)?.getValue())) {
// do something
}
}
I'm not finding a proper article for issue event handling other than random stuff from search engine such as this: https://stackoverflow.com/questions/36668135/how-to-get-a-list-of-modified-fields-with-scriptrunner-on-issueupdated-event
Though for sure I remember seeing a decent article, I'll update if I find it, but above I suppose should work for a start.
Ideally, the listener should read the changeItem to get the new value, rather than check the existing issue, but it won't make a practical difference. I do believe that
changeItem.newstring == 'Yes'
would work, but again, it's practically irrelevant, at best a few nanos in runtime saved.
Hi Radek, sorry I can't get the above script to work? Also, the second piece, 'changeItem.newstring =='Yes'', where would this go in the top script, or what would it replace please? Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.