Hi!
I already know it is possible to generate a string to execute a loop a certain amount of times with getRightPad() as described on Jira Automation - Advanced Branching over smart values
This would generate X,X,X,X,X and you can do split(",") in Smart Value of an advanced branching branch.
What I need is to generate something similar but with numbers. I want to generate a sequence of numbers with a custom interval.
Example: 5 numbers with an interval of 2 -> 2,4,6,8,10
Or 3 numbers with an interval of 4 -> 3,7,11
I'd use this in a loop too and use the number to increment a date with that number of days.
Any ideas?
If you read further in the thread you linked to, you will find I provided an update to my technique to provide the numbers using the {{index}} of the iteration, including the ability to skip by numbers, offset, etc.
Kind regards,
Bill
I actually missed that part. Thanks for bringing it up.
I'm trying to make it work for my specific use-case and will let you know the result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While your solution works I'm blocked because of this bug: [JSDCLOUD-12831] Automation smart value math functions do not work on the Assets object and field Integer attributes - Create and track feature requests for Atlassian products.
{{#varLoopValues.rightPad(varLoopValues.length.plus(varDateDiff), "X").remove("NULL").replaceAll("X","X,").substringBeforeLast(",").split(",")}}{{#=}}{{index}} * {{varInterval.asNumber}}{{/}}{{^last}},{{/}}{{/}}
varInterval is a variable that I created in the automation rule (screenshot) following the workaround from the bug. But for some reason it does not work.
It fails with
Unable to render smart values when executing this rule:
Unknown unary operator * at character position 1: *
I even tried with {{index.multiply(varInternal.asNumber)}}.
For some reason automation rules can not process variables coming from an assets object.
On the other hand, this woks within a Log action:
{{#=}}{{varInterval}} * 15{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Although saving the asset value in the variable helps solve one challenge, your scenario has an additional wrinkle because of this limitation:
Once inside of a long-format iterator such as {{#myList}} ... {{/}} no outside data is accessible. Only data from myList, and lower in scope, is visible.
And so your varInterval cannot be seen in the looping.
One possible fix for this is to back up a bit to the "X" values list, integrate in your interval value, and then use that in the math expression with indices. I will list all of the relevant steps for context, changing some variable names for clarity.
{{varNull.rightPad(varNull.length.plus(varDateDiff.asNumber), "X").remove("NULL").replaceAll("X", varInterval.concat(",")).substringBeforeLast(",")}}
{{#varDateDiffListofIntervals.split(",")}}{{#=}}{{index}} * {{.}}{{/}},{{/}}
We have introduced an intermediary: varDateDiffListofIntervals. This replaces the list of "X" values with a list of your number, varInterval, followed by a comma delimiter.
Then when we iterate over those values to create varLoopCounters, we multiply the {{index}} by the element {{.}} which now contains {{varInterval}}
Please try this and test thoroughly. I recommend adding some "pressure relief" conditions to confirm varDateDiff and varInterval contain what you expect as valid number values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
That's awesome! You really seem to know all the ins and outs of smart values and creative ways to solve more complex cases. You should write an article about it because this is very valuable information :-)
I never used {{index}} and {{.}} for example. But it's really good to know this exists.
Although I wish there was an easier way to achieve this with actual scripting or more features for branching.
Please try this and test thoroughly. I recommend adding some "pressure relief" conditions to confirm varDateDiff and varInterval contain what you expect as valid number values.
You are right. I already added some safety checks like checking for attributes not being empty. But I will add more.
Many thanks for the detailed steps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Charlie Misonne
If you have a close list of potential numbers, for example:
2 -> 2,4,6,8,10
4 -> 3,7,11
Then you can create an automation based on manual trigger and add inputs there:
1. Amount
2. Intervals
3. Starting Point
Then, if its a closed list you can pre-define a lookup table and do IF-Else on the inputs.
see here for more details:
https://confluence.atlassian.com/automationkb/automation-rule-looping-on-a-numeric-value-in-jira-automation-1416563126.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @arielei
Thanks for your answer!
It's actually not a closed list. The amount of numbers and the interval are coming from Jira Assets attributes. So I can not predifine the sequences.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.