Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Loop over sequence of numbers with Jira Automation

Charlie Misonne
Community Champion
June 10, 2025

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?

2 answers

1 accepted

3 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.
June 10, 2025

Hi @Charlie Misonne 

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.

https://community.atlassian.com/forums/Automation-articles/Branching-over-smart-values-in-Jira-Automation/bc-p/1921481#M546

 

Kind regards,
Bill

Charlie Misonne
Community Champion
June 10, 2025

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.

Charlie Misonne
Community Champion
June 10, 2025

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.

image.png

On the other hand, this woks within a Log action:

{{#=}}{{varInterval}} * 15{{/}}
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.
June 10, 2025

Hi @Charlie Misonne 

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.

  • create variable:
    • variable name: varDateDiff
    • smart value: your calculation for this number
  • create variable:
    • variable name: varInterval
    • smart value: your calculation for this number
  • create variable:
    • variable name: varNull
    • smart value: NULL
  • create variable:
    • variable name: varDateDiffListofIntervals
    • smart value: see below
{{varNull.rightPad(varNull.length.plus(varDateDiff.asNumber), "X").remove("NULL").replaceAll("X", varInterval.concat(",")).substringBeforeLast(",")}}
  • create variable:
    • variable name: varLoopCounters
    • smart value: see below
{{#varDateDiffListofIntervals.split(",")}}{{#=}}{{index}} * {{.}}{{/}},{{/}}
  • advanced branch:
    • variable name: varLoopNumber
    • smart value: {{varLoopCounters.substringBeforeLast(",").split(",")}}
      • some actions with {{varLoopNumber}}

 

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.

Charlie Misonne
Community Champion
June 11, 2025

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!

Like Bill Sheboy likes this
0 votes
arielei
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.
June 10, 2025

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

Charlie Misonne
Community Champion
June 10, 2025

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events