How to iterate a list to find a matching item and its index with smartvalues

Adolfo Casari
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 5, 2023

Hi,

I have a variable {{X}} with a list of strings.

Given a smart value {{Y}} (string), I need to find whether there is a matching value in the list X AND its position.

I know how to iterate X and check if Y matches any element, but I don't know how to get the index with the match.

if there is a matching, the idea is then to do {{X.get(index+1)}} and to handle the case when index+1 is out of bound.

Thanks for your help!

 

NOTE: I am trying this:

Result: {{#NombresdeTareas}} {{#if(equals({{.}}, issue.summary))}} {{index}} {{/}} {{/}}

but fails with this error:

 

Could not extract smart value parameter: {{.: Result: {{#NombresdeTareas}} {{#if(equals({{.}}, issue.summary))}} {{index}} {{/}} {{/}}

1 answer

1 accepted

0 votes
Answer accepted
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 7, 2023

Hi @Adolfo Casari 

Just to confirm, is your {{X}} a created variable or an issue field?  If it is a created variable, you would need to split it into a list before it can be iterated upon.

For the other part of your question, I am assuming you are using a created variable...

Created variables are text, and have no object type or attributes.  And so when split a value is just the {{.}} as you have shown.  However that cannot be referenced in the smart value functions.  Instead many of the functions are implemented to handle that case without passing the value.

For example...

  • action: create variable
    • name: varMyVariable
    • value: red,green,blue,alpha
  • action: log a search for a value, "blue"
    • {{#varMyVariable.split(",")}}{{#if(equals("blue"))}}found {{.}} at {{index}}{{/}}{{/}}

 

A complication in your scenario is that once inside of an iterator, only data at that scope and below is visible.  That means that for your iteration on NombresdeTareas, the issue summary is not visible.

One work-around for that is to use the match() function with a regular expression on the variable instead of a conditional inside of the iterator:

{{varMyVariable.split(",").match("(blue)")}}

If you do need the index value from the list, would need to store the index with the value, and include that in your match expression.

Kind regards,
Bill

Adolfo Casari
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 8, 2023

Hi @Bill Sheboy 

ust to confirm, is your {{X}} a created variable or an issue field? If it is a created variable, you would need to split it into a list before it can be iterated upon

It's a created variable.

 

A complication in your scenario is that once inside of an iterator, only data at that scope and below is visible. That means that for your iteration on NombresdeTareas, the issue summary is not visible.

Yes, I found out that. I got an exception error when using issue.summary in the iterator. Any hope for that limitation to get fixed in the future? It's a very bad thing not being able to use any issue fields inside an iterator.

 

If you do need the index value from the list, would need to store the index with the value, and include that in your match expression.

So your saying red-1,green-2,blue-3,alpha-4 right? Can use match with a list? I don't see that option here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/

Thanks a lot for your help.

Adolfo Casari
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 9, 2023

I tried your suggestion but seems that I can't use issue.summary inside the match. The idea is to match the current issue summary againts a list of predefined issue summaries, so I can create the next issue in the list.

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 9, 2023

I am just a Jira user, and so have no visibility to Atlassian changing the scoping behavior for iterators.

Regarding using the index values with the list, first you build the list with an iterator storing in a variable, as you showed for my example.  Then match on the value, such as "(blue*)".  And finally separate out the value with text functions to get your index.

On your next post about using a field like {{issue.summary}} in a match's regular expression, the trick is to first create a variable with the expression, and then use that in the match:

  • action: create variable
    • name: varRegularExpression
    • value: .*({{issue.summary}}).*
  • action: log on the match
    • {{varMyVariable.split(",").match(varRegularExpression)}}

Please adjust the expression / grouping as needed for your scenario.

Adolfo Casari
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 9, 2023

@Bill Sheboy 

One more thing, do you know if list.get(index) works when index is a smartvalue? I just can't make it work, I saved the index in a variable (myIndex) and logs the right number, but with get fails.

Tried get({{myIndex.asNumber}}) but that fails too:

Failed to get value for ParseTareas.split(",").get({{PosicionTareaActual.asNumber.plus(1): {{ ParseTareas.split(",").get({{PosicionTareaActual.asNumber.plus(1)}}) }}
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.
October 10, 2023

At this time, there are at least two versions of the get() function for automation rules: for lists and for lookup tables.

  1. The version of get() for lists cannot take a smart value as a parameter.  (This is what you are trying to do, although you appear to have some typos in your expression.)
  2. The version for lookup tables can take literal values, smart values, and function results.
Adolfo Casari
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 10, 2023

@Bill SheboyThanks for clarifying.

I am under scenario 1.

With your help I was able to iterate the list to find a match for issue.summary, but I don't have a way to get the next item from the list.

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 11, 2023

I am getting confused as to what is the source and the search criteria for your scenario, as you appear to be noting multiple different fields.

Would you please post images of:

  • your current, complete automation rule in one image
  • images of each action / condition / branch details
  • an image of the audit log details showing the rule execution

Those will provide context and help us to have a shared understanding of what you are observing.  Thanks!

Adolfo Casari
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 11, 2023

@Bill Sheboy  the whole rule is too long, but here is the issue:

1) I create a variable and log its value (I get 1)

imagen.png

2) I use it to get the next item in the list.

imagen.png

Log SiguienteTarea and get nothing.

If you put get({{ProximoIndex}}) get an error. If you put get(1) you get the next element. Tried also ProximoIndex.asNumber with no luck.

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 11, 2023

The get() function for a list can only take a number for a parameter.  It cannot take a smart value, either from a field or from a created variable.

If you review my earlier posts, I described how to perform this type of search using a match() function and a dynamic search expresssion.

 

When your rule is longer, you can try using either a screen capture or a browser addon which can scroll to grab the entire image.

Like Aleksandra Leesment likes this
Adolfo Casari
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 12, 2023

@Bill Sheboy 

I was able to come up with the regex to capture the next item from the list after the match with issue.summary

Thanks a lot for your help with this post.

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events