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?

Thanks!

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 Sign up to answer
Community showcase
Posted Tuesday in United States

Topic Tuesday: What's your favorite topic?

Good morning All, Our goal is to get you into the habit of while enjoying your favorite morning drink you are checking the NOVA "space" for topics and comments. Your input is really needed and...

62 views 4 0
View post

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