Nulling an expression's clause when a list count is zero

Martin Cleaver
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.
August 8, 2022

Further to: Solved: Jira Automation get count of issues with current i... (atlassian.com)

How do I make "((labels in ({{triggerissue.labels}}) OR" evaluate to null when labels is an empty list?

I have this expression:

((labels in ({{triggerissue.labels}}) OR otherclause)

If there are any labels I want them to be evaluated, e.g. if triggerIssue.labels is label-1: 

labels in (label-1) or otherclause

But if labels are empty I don't want:

labels in () or otherclause

Because an empty list is invalid

I just want:

otherclause

Per the spec, 

From GitHub - janl/mustache.js: Minimal templating with {{mustaches}} in JavaScript or Jira smart values - lists | Automation for Jira Data Center and Server 8.0 | Atlassian Documentation I guess:

{{#triggerissue.labels}}

((labels in ({{triggerissue.labels}}) OR

{{/triggerissue.labels}}

otherclause

More examples on

Jira smart values - conditional logic | Automation for Jira Data Center and Server 8.0 | Atlassian Documentation

When I place this into an Audit log statement it works fine, omitting the block when the list of labels is empty. (Orange box)

When I place the same into a Related JQL statement it does not, instead it passes "labels in ()". (Red box)

Snag_23c2db30.png

I believe that Related Issues (For JQL) should be able to take smart values.

Solved: Not able to grep related issues by a simple jql wi... (atlassian.com)

1 answer

0 votes
Martin Cleaver
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.
August 8, 2022

.

Martin Cleaver
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.
August 8, 2022

This does not work:

"Function Type" in ("External System") AND ( {{#triggerissue.labels}} ((labels in ({{triggerissue.labels}}) OR {{/triggerissue.labels}} key in ({{triggerissue.Functions to Onboard}}) ) AND project = FN
Error searching for related issues. This is most likely because the following issues don't have a related issue of the type you specified. Try narrowing your search to only include issues that contain links to related issues:: "(("Function Type" in ("Onboardee To Read") AND (labels in () OR key in (FN-505 )) AND project = FN) AND (key != ON-107 )) AND (project in (10811,13703,15606,14203))" - Error in JQL Query: Expecting either a value, list or function but got ')'. You must surround ')' in quotation marks to use it as a value. (line 1, character 60)

So triggerissues.labels is clearly an empty list, which should have nulled out the rendering block around labels

But GitHub - janl/mustache.js: Minimal templating with {{mustaches}} in JavaScript

says for: 

False Values or Empty Lists
If the person key does not exist, or exists and has a value of null, undefined, false, 0, or NaN, or is an empty string or an empty list, the block will not be rendered.

Accordingly, "labels in () OR" should not have been rendered at all.

Martin Cleaver
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.
August 8, 2022

.

Martin Cleaver
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.
August 8, 2022

And it's the same if I used issue.labels instead:

Snag_2171f92c.png

Suggest an answer

Log in or Sign up to answer