Script Runner Send Custom Email condition not working

AndreH March 19, 2015

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

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 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 March 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
AndreH March 23, 2015

Please see attachment of settings

Settings.jpg

0 votes
Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

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.

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

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

AndreH March 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.

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2015

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 March 23, 2015

added attachment

0 votes
Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

Hi Dianne, what you would like to achieve with:

issue.parentObject?.subTaskObjects?.every{it.resolution}
AndreH March 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

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

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.

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

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 March 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?

Suggest an answer

Log in or Sign up to answer