Filtering smart value lists

Hello everyone,

We have recently made an update to the smart value system which enables a few new features. The change enables the conditional logic and other functions to be used inside nested smart values (such as list notation).

This enables some useful tricks, like filtering lists or applying complex functions to fields on an object.

 

Why would you do that?

Previously, if you had a list smart value, it was impossible to selectively display information inside the list based on some condition.

Take the example of issue comments. Imagine you would like to print out just the internal comments, and ignore the public comments.


Screen Shot 2021-10-07 at 3.38.01 pm.png

 

How would you do that?

You now can use an if statement to filter the list to only get the internal comments

{{#issue.comments}}
{{ if(isInternal, body) }}
{{/}}

This results in
Screen Shot 2021-10-07 at 3.43.16 pm.png

This can be used to also create some much more complex messages as well:

{{#issue.comments}}
{{#if(isInternal)}}
- An internal comment by {{author.emailAddress.abbreviate(5)}}: {{body}}
{{/}}
{{/}}

Screen Shot 2021-10-07 at 3.54.29 pm.png

There are a wide number of functions that can be used, such as:

{{#issue}} {{#=}} {{number_field}} + 10 {{/}} {{/}}

{{#lookupIssues}} Send web request with summaries {{urlencode(summary)}} {{/}}

{{#issue.comments}} Reading comment at time {{now}} {{/}}

{{#issues}}
{{#if(gt(comments.size, 10))}}
Issue {{key}} has more than 10 comments!
{{/}}
{{/}}


Where can I find more information?

More information about the functions and smart value capabilities can be found in our smart value documentation. More information and examples will be posted there as we continue to develop more features in the smart value system.

Cheers!

Sam

24 comments

Bill Sheboy
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.
October 18, 2021

Hi @Sam Harding 

Given your examples use {{issue}}, {{lookupIssues}}, and {{issues}} it appears this change works with both Cloud and Server/Data Center.

Is that correct?

Thanks, and kind regards,
Bill

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 29, 2021

Hi @Bill Sheboy 

This change was released only for cloud. The behaviour may vary with server/data center.

Cheers

Sam

Like Bill Sheboy likes this
Bill Sheboy
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.
January 27, 2022

Hey @Sam Harding 

Would you expect created variables to work in these types of conditional tests, within list iterators?  It seems like they do not.

Thanks,
Bill

Oliver Berger March 17, 2022

After fighting the whole day with mustaches and documentation, which ends where it gets interesting or is just false, here is a "filter for lists".

Assuming you have a list of fixVersions, and you are looking for the ones matching a specific regex, like in my case "H1-2022".

This one gets a comma separated list of matching ones.
{{#issue.fixVersions}}{{#if(exists(name.match("(H[1,2].?\d{2,4})")))}}{{name}}{{^last}},{{/}}{{/}}{{/}}

this one does the opposite:

{{#issue.fixVersions}}{{#if(not(exists(name.match("(H[1,2].?\d{2,4})"))))}}{{name}},{{/}}{{/}}
Maybe it could be enhanced, but for today, I'm DONE!
cheers Oli
Like # people like this
Bill Sheboy
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.
April 28, 2022

Ping...to the Atlassian team members following this thread:

Should created or branch variables work as parameters to conditional tests (and their included functions) in smart value, list filtering?  It seems that they do not.

Example use case:

Given a list of user account id values driving an advanced branch, use each account id to loop and conditionally filter a lookup issues result so that each user receives a message/email relevant to them.

Thanks,
Bill

Bill Sheboy
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 6, 2022

Hi, community!

While helping with a question using list filtering, I observed the conditional logic documentation has some ambiguity.

After a bit if testing it appears the documentation means that OR() and AND() can only have exactly two parameters: or( A, B).  With more values, conditional logic silently evaluates to null and raises no rule errors.  These functions are commonly understood to support chaining results, and so the documentation may be misunderstood.

When there are more than 2 conditions, nesting is required:

{{#if(or(or(conditionA, conditionB), or(conditionC, conditionD)))}}success!{{/}}

Thanks,
Bill

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2022

Hi @Bill Sheboy 

Addressing your older comments regarding the use of custom variables as parameters, there is a bug around the type resolution of custom variables when used as params which causes broken functionality. I have raised a ticket here https://codebarrel.atlassian.net/browse/AUT-2430

As for the second question regarding the need for nesting conditions, your observations are correct. The functions all expect exactly 2 parameters, any other number will not evaluate the function. I agree this can be better reflected in our documentation, and have raised it internally with our content team.

Thanks as always for your feedback,
Sam

Like Bill Sheboy likes this
Deniz Karadal August 16, 2022

Hi @Sam Harding ,

After checking your solution regarding "Filtering smart value lists", I need your little assistance regarding it because on our data center version of Jira, I could not make it work by using the following code snippet. However, by using "If" statement using condition in automation, it works as expected.

Unbenannt.JPG

Regards,

Deniz

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2022

Hi @Deniz Karadal 

The problem you are facing is that the function `gt` is not valid with that usage. In smart values, `gt` is a function on numbers only. Can you try changing your smart value to

{{#if(issue.key.split("-").get(1).asNumber.gt(100))}}
{{issue.key.split("-").get(1)}}
{{/}}

 Also note the internal smart values used inside the conditional block must also have their own {{ }}

Let me know if that works for you

Cheers
Sam

Like Bill Sheboy likes this
Deniz Karadal August 17, 2022

Hi @Sam Harding

No output has been printed out unfortunately.

Regards,

Deniz

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2022

Hi @Deniz Karadal 

That's strange, apologies for the solution not working for you, it seems to work as expected for my test cases.

Can you confirm for me, what printing the following smart value to the audit log produces in your rule? Cheers

String: {{issue.key.split("-").get(1)}}
Number: {{issue.key.split("-").get(1).asNumber}}
Conditional: {{issue.key.split("-").get(1).asNumber.gt(100)}}
Deniz Karadal August 17, 2022

Hi @Sam Harding

Please check the following.

Unbenannt.JPG

Regards,

Deniz

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2022

Hi @Deniz Karadal 

Seems like the split may already be returning a number. Can I confirm, you are running in cloud?

Can you try

Conditional: {{issue.key.split("-").get(1).gt(100)}}
Deniz Karadal August 18, 2022

Hi @Sam Harding 

As I indicate out on my first post, we are using data center not cloud. However, your last code snippet returns nothing unfortunately.

regards,

Deniz

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 18, 2022

Hi @Deniz Karadal 

Apologies for missing that part of your first message. A version of this that should work for data center is 

{{#if(number(issue.key.split("-").get(1)).gt(100))}}
{{issue.key.split("-").get(1)}}
{{/}}

Give that try, hopefully that fixes it for you

Cheers
Sam

Deniz Karadal August 19, 2022

Hi @Sam Harding 

Thanks. It seems that it works but this time I was lucky to find your post. However, there is no valuable information which I can search for such cases regarding it or at least I could not find upon my search. What is the best recourse or link on Atlassian side at first stage?

Regards,

Deniz

Bill Sheboy
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.
October 18, 2022

Hi @Sam Harding 

Would it surprise you to learn that smart value, list filtering does not currently appear to work with team-managed projects (TMP) as compared to company-managed projects (CMP)?  Please see this thread: https://community.atlassian.com/t5/Jira-Software-questions/Specifying-a-field-value-to-be-retuned-for-a-Smart-Value-lookup/qaq-p/2163708

And here are a couple of expressions on a Lookup Issues result which unexpectedly return nothing for TMP but which work for CMP:

Here is a once-filtered list of issues: 
{{#lookupIssues}}
{{#if(equals(statusCategory.name,"In Progress"))}}
{{key}} - {{summary}} {{statusCategory.name}}
{{/}}
{{/}}

 

This second example was to be used in conjunction with showing a separate message when there are no results to the lookup, rather than a blank space in an email.

Here is a twice filtered list of issues: 
{{#if(lookupIssues.size.gt(0))}}
{{#lookupIssues}}
{{#if(equals(statusCategory.name,"In Progress"))}}
{{key}} - {{summary}} {{statusCategory.name}}
{{/}}
{{/}}
{{/}}

 

Thanks, and kind regards,
Bill

Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 25, 2022

Hi @Bill Sheboy 

Thanks for pointing that out. It doesn't entirely surprise me, as there are some differences in the field ids/names between the two. The smart value system itself is the same between the products, so I suspect it would be an issue with field mappings.

Im curious, does the smart value

{{lookupIssues.statusCategory.name}}

return a valid list for both your product instances?

What about

{{#lookupIssues}}
{{equals(statusCategory.name, "In Progress")}}
{{/}}

In particular, does the second one return blank, or does it return a bunch of true or false?

I will have a look at these cases myself as well

Cheers
Sam

Like Cedric Jimenez likes this
Trang Ngoc Nguyen March 11, 2023

Hi @Sam Harding! I know that you wrote above that the functionality might not work well for Jira Data Center, but since the functionality is officially documented in Data Center version so I would bet my luck here :D 

 

I am trying to recreate the customer notification system by using Automation in our Jira Data Center version 8.20. I want to implement a rule which is: When a request participant is added => Notify the added participants.

The "send email" action in Jira automation does not have the added participant as a choice for receipients, and unfortunatly Jira Data Center does not have the smart value {{addedFieldChange.values}} as it is in the Cloud, so I am thinking to work around it with a smart values as follow:

{{#issue.customfield_14061}} 
{{# if(equals(accountId, fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()))}}
{{emailAddress}}
{{/}}
{{/}}

 However for some reasons the returned data is empty (though it should actually gives a value). I have done a lot of testing:

  • fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() was tested alone and gave the correct value
  • If fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() is replaced by a string (e.g "JIRAUSER12345"), the returned data is correct
  • If replace fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() by another simple issue.description smart value (and this value is exactly the same as the working string), then the returned data is empty.
  • The "If" condition work with fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() and description, meaning {{# if (equals(issue.description, fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()))}} works.
  • But when it is for the Request Participants field, it looks like the #if condition doesn't work with two smart values. For some reasons Jira is thinking that the two values are not the same.

Could you please suggest how I would solve this problem? Thank you very much!

Cedric Jimenez April 4, 2023

Hello, 

I'm trying to do an automation calculating the sum of story points subtasks for an issue, but not for all the subtasks, i'd like to filter this list, AND do the sum of the filtered list, but really no idea on how to do that.

Summing all the subtasks is easy : 

{{issue.subtasks.Story Points.sum}}

 

Any idea on how to do the same for the subtasks with a particular label or status ?

Bill Sheboy
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.
April 4, 2023

Hi @Cedric Jimenez 

I do not know if all of the data for the subtasks is stored with the parent, or just a subset.  And so you could try a couple of things:

1) Iterate over the subtasks, wrapped in a math expression, to add them:

{{#=}}0{{#issue.subtasks}}{{#if(your condition here)}}+ {{Story points}}{{/}}{{/}}{{/}}

2) Use JQL to get the subtasks you want in a Lookup Issues action, and then sum the value.

Kind regards,
Bill

Like Cedric Jimenez likes this
Bill Sheboy
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.
December 19, 2023

Hi @Sam Harding 

I have an edge-case question based on something asked in a community post:

When using smart value, list filtering, what is the maximum number of matches that can be found?  Is it up to the list limit or is it a lower value, such as the 100 limit used for other things like branches, lookups, etc.?

The scenario was someone was writing information to comments in one rule, and then later trying to parse out data from comments in a different rule later.  Could the filtering on comments fail to return all possible matches due to a limit?

Thanks, and kind regards,
Bill

Steve Letch December 21, 2023

@Trang Ngoc Nguyen 

We just add approvers to the request participants, then add a comment, that way everyone involved in the ticket, including the approvers gets a customer notification of the comment that it's waiting on the approvers :)

Steve Letch December 21, 2023

Something I've working through at the moment is modifying our customer comment approval reminder function to pull the approver values directly from the status, instead of from the users held in a user picker that's been set based on an assets object that was selected.

 

Normally if someone wants to be added to a security group, they select it in the portal and the approver is pulled from the value held against the assets object, into a user picker field, then they're used as the approver. Then we have a rule that runs 3 times a week to pull the approver into request participants and add a comment stating approval is waiting on them.

 

If in the case of one of our workflows, the approval is driven not by the contents of a user picker field that's inherited it's value from an assets object, but by user values held directly against the object selected in the assets field.

 

I've figured out how to add this value to request participants via:

 

{
"update": {
"customfield_13703": [
{
"add": { "name": "{{#issue.customfield_13702}}{{approvers.approver.name}}{{/}}" }
}
]
}
}

Where 13703 is Request participants and 13702 is the status. This all works fine, however when I go to add my comment

 

Waiting for approval from {{#issue.customfield_13702}}{{approvers.approver.displayName}}{{/}} for {{Approvals duration.durationAsString}}

 

It's also pulling in the user from the previous approval stage (line manager) (we have two stage approval on some requests, line manager, then a list of approvers)

 

Trying to figure out how to make 

{{#issue.customfield_13702}}{{approvers.approver.displayName}}{{/}}

Only pull in the names that have

"approverDecision": "pending"

against them

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events