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!
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...
Kind regards,
Bill
Thank you so much Bill, that works perfectly!
I was under the impression lookupIssues.components would already flatmap the components.
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.