ScriptRunner - why doesn't Listener adhere to Conditions?

Using the Adaptavist ScriptRunner for Jira Plugin, I want to test 2 conditions to allow an email to be sent.  Both conditions rely on checking values of custom fields.

Specifically, the one line I have in my Condition section is:

(cfValues['Reported by'] != null) && (cfValues["Customer"] != "xyz")

I know the fields are populated correctly because when I run the Preview mechanism to see what my email looks like, the validation step that tests the Condition is returning true or false correctly based on different issues I throw at it.

However, I've already seen where an issue that tested with a false condition was still sent out.  My concern is that warning in the Preview mode that states ".......note that for listeners the condition can't normally be tested".

What does 'normally' mean in this context?   Is there any way to have the Condition function as expected here?


1 answer

The note about listeners indicates that you can't reliably test a listener on something like an IssueUpdated event. Many conditions rely on things like comparing the current value of a custom field to the value it's being changed to. Those conditions only make sense when the event is firing, not on an issue in stasis. For your use case, that doesn't seem to apply.

As I'm reading your condition, it says, Only send the email if both of the following are true:

The 'Reported by' custom field is not null
The Customer custom field does not equal the string 'xyz'
If that's not what you intend, then you may simply need to rewrite the condition.

If you can reliably reproduce the issue, there are a few things I would check:

1. Does using the custom field manager instead of cfValues work?

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def reportedBy = customFieldManager.getCustomFieldObjectByName("Reported By")
def customer = customFieldManager.getCustomFieldObjectByName("Customer")
issue.getCustomFieldValue(customer) != 'xyz' && issue.getCustomFieldValue(reportedBy) != null

2. What is the specific configuration of your listener? What events is it firing on?
3. Is there anything specific that you need to do to reproduce the issue? Like, is the problem only occurring in a particular project?

Suggest an answer

Log in or Join to answer
Community showcase
Maarten Cautreels
Posted Thursday in Off-topic

Friday Fun: What's your favourite beer/drink

As a Belgian, beer-lover and home brewer, beer is one of my great passions. I love the fact that with just a few ingredients (usually just water, hop and malt) you can create so many different tastes...

282 views 38 9
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot