Smart value block helpers (#if, #for) in Jira Automation fail or behave inconsistently when using functions inside, especially with dynamic property access, array iteration, and function calls in block conditions or within loops.
Example-
Given config = [{"version": "1.2.3", "env": "PROD"}, {"version": "1.2.4", "env": "TEST"}]
When attempt to iterate and filter using -
{{#for(jsonStringToObject(config))}}
{{#if(equals(version, "1.2.4"))}}
{{env}}
{{/if(equals(version, "1.2.4"))}}
{{/for(jsonStringToObject(config))}}
Then
-this produces no output (empty),
- no error is shown,
- documentation is unclear if this feature has issues.
Expected result:
- Block helpers should support function calls and dynamic conditions,
- If not supported, documentation should clearly state the limitations and advise a roadmap.
Any suggestions?
Hi @Joshy Chirayath -- Welcome to the Atlassian Community!
First, your initial expression is not a valid JSON string; thus, the jsonStringToObject function cannot parse it. Please try this:
{
"config" : [
{
"version": "1.2.3",
"env": "PROD"
},
{
"version": "1.2.4",
"env": "TEST"
}
]
}
Next, there is no #for() function in automation rule, list iteration: there is a long-format iterator and an inline-format (which just uses dot-notation on one object / attribute at a time).
Please try this to get the result I believe you are seeking with a conditional, list filter:
Assuming your above JSON text was stored in a variable named varMyJson.
{{#jsonStringToObject(varMyJson).config}}
{{#if(equals(version, "1.2.4"))}}
{{env}}
{{/}}
{{/}}
Note that the "config" attribute is referenced after the function in order to provide a list to the iterator.
Kind regards,
Bill
Thank you , it works!
I'm however wanting to use a variable for the search, e.g. thisVersion = "1.2.4" in which case this doesn't seem to return any value. Thoughts?
{{#jsonStringToObject(varMyJson).config}}
{{#if(equals(version, thisVersion))}}
{{env}}
{{/}}
{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome; I am glad to learn that helped!
Regarding using the variable for the list filter, that will not work directly: there is a long-standing limitation where only data from the iterator scope, and lower, can be accessed inside a long-format iterator.
Here is one of the open defects / suggestions for that limitation.
With Jira Cloud and your specific scenario, there are two possible workarounds:
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.