Script Runner Send Custom Email condition not working


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

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.

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!

Hi Dianne, what you would like to achieve with:


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

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?

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.

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?

added attachment

Please see attachment of settings


Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira

How you can achieve compact and easy-to-maintain workflows in your JIRA( Server)

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...

235 views 0 0
Read article

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