Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Static Loop in Jira Automation

Jan-Otto Kröpke March 14, 2024

Hi,

I would like todo a static loop in jira automation.

I figure out, that I can use the smart variable:

{{IF(issue,"TopicA,TopicB","TopicA,TopicB").split(",")}} loop over TopicA and TopicB.

 

Is there an less hacky way to archive this?

I tried

> {{"TopicA,TopicB".split(",")}} 

but, it wont work.

1 answer

0 votes
Kalyan Sattaluri
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 14, 2024

Hello @Jan-Otto Kröpke  Welcome.

Syntax for If conditional is:

  • {{if(smartValue, "value if true", "value if false")}} allows you to add a specific value when the condition is not matched.

So in what you have shared in your post, its not looping over anything. It is always evaluating to false because your smart value (issue) is always evaluating to issue key of rule which triggered it and its typically not of the format "topic A, topic B".. But because your value for "false" is the same, you essentially always pass that If condition. And I am not sure why split is included, but thats for another discussion.

A normal use case of "if" would be something like below:

{{IF(equals(now.jiraDate,"2024-03-14"),"ABC","PQL")}}

if I execute above statement today, I will get "ABC" because today's date is 2024-03-14 and so it passed. if I execute the same statement tomorrow, I will get "PQL" because If statement will evaluate to false. Kinda unnecessarily clumsy example but thats how to use If condition.

Now to your iterate / loop topic, you need to look into lists /arrays in the context of Jira and how to work with them based on your use case. If you just want to list them out, you can reference the field directly, like {{issue.fixVersions.name}} and Jira will output the list.

OTOH, if you want to do conditional checks for each, you coudl some thing like below:

{{#issue.fixVersions}}
{{#if(equals(name,"MY-RELEASE"))}}
{{releaseDate}}
{{/}}
{{/}}

where we are looping and checking if fixVersion name is "MY-RELEASE", only then print the releaseDate.

Or to take it to extreme example, you could have field with array of lists so that could be something like below:

{{#issue.customfield_ABCD}}
{{#approvers}}
{{#if(equals(approverDecision,"declined"))}}
{{approver.displayName}}
{{/}}
{{/}}
{{/}}

 

Finally, if you are in Cloud, Jira gives a UI way called Advanced Branching which does For/Each on a list so you can do that instead of smart value way listed above.

So, thats a little overview on the topic. Let us know what do you mean "static loop" cause its not clear from your post.

Hope it helps.

Jan-Otto Kröpke March 15, 2024

Hey @Kalyan Sattaluri

thanks for the explanation. I understand the if function. We can keep the focus on loop functionality.

You explained that I can loop through smart variables like {{issue.fixVersions.name}}. The case is well documented.

But instead using a smart variables, I would like to loop over a static list of items instead using a issue field as source.

Kalyan Sattaluri
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 15, 2024

Hello @Jan-Otto Kröpke 

If you have a smart value variable called {{varMyList}} and you put in TopicA, TopicB as values. (the values in varMyList are text/ string and you need to use split to convert).

If you want to loop over this list, you would do:

{{#varMyList.split(", ")}} * {{.}} {{/}}   -> Prints * TopicA * TopicB

You can do advanced branching from UI on {{varMyList.split(", ")}} and do/achieve the looping logic like above step.

So if your "static" list is first stored in a variable, you can act upon it like you would any field. Maybe thats the piece you are missing. If not, I am lost on what you mean static list. 

 

 

 

 

Like Jan-Otto Kröpke likes this
Jan-Otto Kröpke March 18, 2024

Thanks you.

 

Unfortunately I cant mark comments as accepted answers.

Suggest an answer

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

Atlassian Community Events