Advanced field editing in automation results in invalid JSON

Daniel Welzel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 6, 2025

I have created an automation that upon issue creation, editing and deletion branches to the parent issue, fetches all the child issues and then sets the components of the parent issue to be an aggregation of all components of the children.

In the last "Edit Issue" action I have this mustache code to do that:

{ 
"update": {
"components": [
{
"set": [
{{#lookupIssues.components}}
{"name": "{{name}}"}{{#unless @last}},{{/unless @last}}
{{/lookupIssues.components}}
]
}
]
}
}   

 However, this results in invalid JSON and I don't see why that happens.
Any help is much appreciated!


1 answer

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.
February 6, 2025

Hi @Daniel Welzel -- Welcome to the Atlassian Community!

There are several errors in that JSON, including the list handling.

Before we get to those, let's confirm your scenario.  Do you want to replace the Parent issue's Components or add additional values to them?  Let's assume you want to replace the values. 

 

Lookup Issues contains a list of values, and Components are also a list.  This creates a list-of-lists for the field (which appears as a list of arrays within a rule).  And so those must be aggregated and reduced to remove duplicates.

Next, when replacing / setting the value of a field, I recommend using the "fields" syntax as a shortcut to reduce the chance of errors.

Finally, when iterating a list and one wants to have something for everything except the last item, the syntax is {{^last}} something {{/}}

Putting those together, we get this expression:

{ 
"fields": {
"components": [
{{#lookupIssues.components.name.join(", ").remove("[], ").remove("[").remove("]").split(", ").distinct}}
{ "name": "{{.}}"}{{^last}},{{/}}
{{/}}
]
}
}

How that works...

  • join together all of the component fields for the issues in the lookup results, with a comma-space delimiter
  • remove any empty arrays with "[], "
  • remove any remaining array brackets
  • split the results back into a list
  • use distinct to remove duplicates
  • and then iterate to create the JSON for each entry

 

Kind regards,
Bill

Daniel Welzel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 6, 2025

Thank you so much Bill, that works perfectly!
I was under the impression lookupIssues.components would already flatmap the components. 

Like Bill Sheboy likes this

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