Split results in an array, but can't be iterated over

Inna S March 28, 2023

Hi, 

I'm traying to split a string and then iterate over the resulting array members.

The string is: 

string.jpg

The split action is:

split.jpg

The result is:

target.jpg

The iteration attempt:

advanced.jpg

And finally the current value inside the loop is:

currentvalue.jpg

What am I doing wrong?

Thank you.

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.
March 28, 2023

Hi @Inna S 

In your images, you are showing multiple different variable names for the smart value expressions, and they do not seem to match. 

For example, the Advanced Branch is showing {{TargetVersionsList}} and you do not show what that contains.  Normally the branch is where the split occurs on an object or string.

Would you please post an image of your complete rule and audit log details?  Those may provide more context for what you are describing.  Thanks!

Kind regards,
Bill

Inna S March 29, 2023

Oh, sorry, I renamed the var and it is now TargetVersionsList, the result is the same:

target.jpg

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.
March 29, 2023

Without seeing your complete rule, I suspect another problem is there is no split of the variable before it is used in the advanced branch.

Inna S March 29, 2023

Here is the rule

CloneRule.jpg

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.
March 29, 2023

When you are trying to post an image of a longer rule, I suggest selecting the trigger in the rule editor, and then using a scrolling page capture tool.  That will show the entire rule in one image.

Would you please post an image of the advanced branch?  Again, I suspect the problem is the source smart value is not split, and so the branch tries to process it as one thing (not several).

Inna S March 29, 2023

I'll try to do this.

This split trouble is what brought me here:

the field that gets read correctly is a string, as shown in the 'found on card' log entry.

And then the split is supposed to happen, as shown above.

And this split just does not work.

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.
March 29, 2023

Can you show me just your advanced branch setup and the smart value (or created variable) that feeds that?  With those we can probably get the branch working fairly quickly, as the split may just be in the wrong place.

Like Inna S likes this
Inna S March 29, 2023

Ok, I've replaced the coma (",") with an underscore ("_") in the string, and found that the resulting var is in fact the list.

But I can't seem to access an individual member of the new list.

sample.jpg

Inna S March 29, 2023

rule1.jpg

Inna S March 29, 2023

split1.jpg

adb.jpg

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.
March 29, 2023

When you have a list, you can access a specific item by: first, last, an index with get(index), or by match() with a regular expression.

If you instead need all of them, try the split() to feed the advanced branch.

Inna S March 29, 2023

It's funny, when I add ".last" to the split statement, it brings the second part ok.

So the split works, but the loop does not bring 'every item' 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.
March 29, 2023

Okay...that is curious.  If you can find a way to post the entire rule and audit log details images, that may help explain it.

Inna S March 29, 2023

2023-03-30_0-14-46.jpg2023-03-30_0-15-42.jpg2023-03-30_0-16-32.jpg

Inna S March 29, 2023

2023-03-30_0-19-11.jpg2023-03-30_0-18-32.jpg

Inna S March 29, 2023

I'll have to call it a night, will be glad to hear if you or anyone would have an idea.

Thanks a lot, @Bill Sheboy 

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.
March 29, 2023

Thanks for the images of your rule, and the action setups for the variables.

Based on what you show, the audit log does show each value is getting processed.  If the advanced branch still matches your earlier images, this seems correct. 

What is not working as you expected?

2023-03-30_0-19-11.jpg

Inna S March 29, 2023

The 'current' entry is expected to be set to each of the, 3 in this case, parts of the string. This log action should appear 3 times in the audit log and not once. Otherwise how can I take action on them one by one?

Say, I need to clone the issue for several releases.

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.
March 30, 2023

Yes, I understand what you are saying: you expected to see this three times:

"current myEntry is ..."

For some design reason, the implementation of branches is "smart" in that it collapses these down in the audit log because the prefix is the same, even though the loop does process three times.  I personally consider this as a defect...regardless...

You can confirm this is indeed processing for each by doing something the rule cannot, either your desired action (i.e., clone the issue) or to write a comment with the same text to the issue.

Inna S March 30, 2023

Unfortunately this does not work

2023-03-30_17-17-48.jpg

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.
March 30, 2023

Please post an image of the advanced branch action for myEntry.  Thanks!

Inna S March 30, 2023

2023-03-30_21-47-35.jpg2023-03-30_21-47-00.jpg2023-03-30_21-46-10.jpg

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.
March 30, 2023

That appears to be the cause: a created variable is text, not an object or list.  Please try splitting the variable in the advanced branch source with:

{{myList.split(",")}}
Like Inna S likes this
Inna S March 30, 2023

This is much better, basically resolves my specific problem. Thanks a lot!

But I still do not see why the original split replaces the "_" with "," in a string instead of creating an array?!

2023-03-30_22-20-36.jpg

 

2023-03-30_22-21-49.jpg

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.
March 30, 2023

I am glad to learn that worked!

Regarding your question about the first split on underscores...

The first split on underscore created a list (not an array), and when that was then put into the created variable, it was automagically joined back into a text string separated by commas.  Effectively it did this:

"12.13.14.15_87.98.65.12_44.5.78".split("_").join(",")

If you had seen values with square brackets, that would be an array...but you could not use the list functions on that value.  It would require more functions to convert to a list.

Someday in the future, I hope Created Variables will be capable of storing objects (like the new Lookup Tables feature), and so the double conversion you did would not be needed.

Like Inna S likes this
Inna S March 31, 2023

How is this an acceptable behavior?

Somewhere in this journey I had items inside square brackets, but I could not see why would the split function create anything but an array to iterate over.

More than that, 

original string is coming from a lookup result: I search for an issue with lookup, then pick the single field of type "short string". And then invoke a split on it. This does not work.

Not in a 'create variable' step and not in the advanced branching.

But when this lookup.field result is assigned to a variable, this intermediate variable then can be used in the advanced branching to get an array.

What a mess.

Thank you so very much for your patience and help, @Bill Sheboy 

You saved me the use of external tool for this particular task!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events