It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner Send Custom Email condition not working

AndreH Mar 19, 2015


I have Jira 6.3.5 with Script Runner 3.0.6

Script Listeners - Send a custom email
Events: Issue Closed

Conditions -
issue.subTasks.size() > 2

The problem is that the labels condition is not working (issue.labels.any{it.label=='NewHire'}).
It is sending and email regardless of the labels, the email need to be sent only if it matches that of a NewHire label.

Any idea why it is ignoring the labels condition?

Thanks in advance.

4 answers

1 accepted

0 votes
Answer accepted
JamieA Mar 25, 2015

You're misunderstanding how conditions work. The entire script is evaluated, and the result of the last line determines whether the condition passes or not.

You can either just return the last line, which is suitable for one-liners, or explicitly use variables and / or a return statement.

So you want something like:

(! issue.isSubTask() && issue.subTasks.size() > 2) && 
	issue.labels.any{it.label=='NewHire'} &&
	(issue.isSubTask() && issue.parentObject.subTaskObjects.every { it.resolution })

Your conditions as you wrote them don't really make sense, because you're checking that there are more than 2 subtasks, and also that all the subtasks siblings are resolved.

AndreH Mar 26, 2015

I used - issue.labels.any{it.label=='NewHire'} && (issue.isSubTask() && issue.parentObject.subTaskObjects.every { it.resolution }) and removed the sub-tasks greater than 2. It is working great! I tried the && before, however the part I was missing was another && for the subtask. Thanks again!

0 votes

Hi Dianne, what you would like to achieve with:

AndreH Mar 20, 2015

The email needs to be sent only when all of the sub-tasks are closed. I have created new sub-task issue types, so the parent ticket has ootb sub-tasks plus custom sub-task issue types

You should not be able to have a subtasks hierarchy, I mean you should not be able to create a sub task from another subtask. I see it as, I have this issue that must have at least 2 subtasks and a label "NewHire". The current issue is not a subtask itself so you can't retrieve the parent. That parentObject will always be so every time your condition will be false.

I've tried to reproduce your problem but the only issue I have is related to the third line and not the second one. I would suggest using this syntax (it has the same behaviour as your code but it's simplier): "NewHire" in issue.labels*.label

AndreH Mar 20, 2015

So if the parent issue has 33 sub-tasks, how do I check to see if the last sub-task is closed? and then send the email?

0 votes

You may try something like...

"NewHire" in issue.labels*.label
if (issue.isSubTask()){
    issue.parentObject.subTaskObjects.every {it.resolutionObject}
} else 

without using "issue.subTasks.size() > 2"
Because you can't say this issue must have more than 2 sub tasks and its parent must have all its sub tasks closed. Simply because you can't have a subtask of a subtask.

The last part means that if you are not closing a subtask the mail would not not be sent.

In this case I also expect to have the label "NewHire" in the sub task and not on the parent one.

AndreH Mar 20, 2015

Yes NewHire is the label in the Sub-task. I tried the above code, the issue is when there is any label in the Sub-task, it still sends out an email. It's ignoring the NewHire label. I've tested just with a label ABC and it still sends out an email.

I can't reproduce the issue related to labels. May I have a screenshot of the settings you used on the listener configuration screen?

AndreH Mar 23, 2015

added attachment

0 votes
AndreH Mar 23, 2015

Please see attachment of settings


Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira Software

Early Access: If you use Jenkins and Jira Software Cloud, you need to read this!

The Jira Software Cloud Team has been busy working on a simple, secure, and reliable way to integrate your build and deployment information from Jenkins with Jira Software Cloud. This means you don’t...

316 views 0 9
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you