I have an automation rule in which I:
The problem is the "for each: smart value" branching doesn't actually iterate over the matches but instead treats the result of `match` as a single value.
Does anyone know how I could loop over the matches one by one?
As mentioned in my reply above, the audit log smartly collapses log messages which creates the impression that the whole list is a single string. It is, in fact, not though which means you can use operate on the element inside the branch exactly like you'd expect.
Thanks everyone for the quick help! This is a great community.
Hi @johannesm
I find that advanced branching occasionally needs "help"; sometimes it parses the source as a list and sometimes not. Two approaches for your source list are:
{{varMyBranchSource.split(",")}}
{{#webResponse.body.body.match(".*(#[0-9]*).*")}}{{.}}{{/}}
And also...I highly encourage you to always make variable names (created or branch) different from all possible reserved words. In your advanced branch you call it match and I would suggest always prefixing, such as varMatch.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the master class, @Bill Sheboy !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First of all, thanks for pointing out that creating a variable forces to text. I was not aware and that explains some failures I saw while testing other things.
I tried both your suggestions but the behavior wasn't any different. One thing I did notice during testing though is that the audit log appears to smartly collapse log messages.
When I used
>{{varMatch}}<
I noticed the angular brackets being added to each element in the output.
So ultimately, the audit log just makes it seem as if the value is a single string by collapsing the log messages into a single line.
Which means it worked correctly from the start and I just didn't realize because the log output kept me from trying to proceed. 🤦♂️
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We've all been there.. I confess I missed it completely, too.
Regardless, I'm glad to hear it's working!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello! Welcome to the community!
One thing worth trying is figuring out whether the output of your regex is a list or a string - if it was a list I would expect it to work on your setup so let's check.
To do that, try logging one of these on the audit log:
{{match.first}}
{{match.get(3)}}
Taken from: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/
If your match variable is a string, we'll probably get an error on the above and you'll need to .split your regex output to create a list.
Look for the .split function here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/
Let us know the output of the audit log tests.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help Filipi!
It seems like the output of calling `match` is a list because calling `first` on it gives the first element.
However, inside the for each branching I appear to get the whole list as a single string and calling `first` there does nothing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now that you know it's a list, you can iterate on the list as a Smart Value (not in a branch). I'm not sure if that will achieve your goals, but a lot of list processing can be done with Smart Value notation. See the Combined function examples.
For more complex handling in Smart Value lists, check out the conditionals you can use while iterating on a list.
Note that all these will do some processing of the list, resulting in some text that you would use elsewhere (e.g. in an email, or to set a variable). You don't actually get to manipulate the list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Mykenna! This made me realize that I could "unroll" the branch-loop and instead manually access list elements by index. This ends up with a quite lengthy automation rule but at least works if you know a reasonable finite upper limit for the length of the list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.