Script Runner Send Custom Email condition not working

Hello,

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
issue.labels.any{it.label=='NewHire'}
issue.parentObject?.subTaskObjects?.every{it.resolution}

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:

issue.parentObject?.subTaskObjects?.every{it.resolution}

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 
false

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

Settings.jpg

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,774 views 18 21
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