Hey all, this one is really a doozy and I can't figure it out.
User request is to add the values from one asset based field of the child to the parent when child is closed. The issue I have is whatever I do every automation rule fails or clears previus values and does not add new ones.
I have read many the docs and consulted with Atlassian AI, Google AI, ChagtGPT, but all seem to be stuck in a loop.
I have to check the values the parent has and the ones child has and then deduplicate them and try to instert them to the parent - this is because I cannot use a simple "add" operation for Assets-based custom field - meaning: only "set" is supported. This means you can't append values to an Assets field; you can only overwrite the entire field with a new set of values.
Tried different variables/smart values and even changed the rule to be a global one so I could use Lookup objects, which was one of the suggestions.
For example, this is a variable "combinedFeatures" to combine the Features (the name of the assets based field I am trying to copy/add):
{{#triggerIssue.fields.customfield_10196}}{{id}},{{/triggerIssue.fields.customfield_10196}}{{#issue.fields.customfield_10196}}{{id}},{{/issue.fields.customfield_10196}}
In debug log I see that it produces:
combinedFeatures: [ { "id": "4046" } , { "id": "4049" } ]
And then I am editing the parent field inside a branch with this JSON:
{
"fields": {
"customfield_10196": {{combinedFeatures}}
}
}
This example is one of the simpler ones and it is failing with:
(ID 4046 did not have the expected format (customfield_10196))
I had also other ones that had keys instead of ids
combinedFeatures: [ { "key": "INTASSET-4046" } , { "key": "INTASSET-4049" } ]
and the rule reported
Issues edited successfully
while it only deleted values from the parent field where it should add them. I have tried many combinations.
Anybody had a similar issue? What would be a solution?
Hi @janez_m
You need the 2nd option at least, with the keys.
It might be an option to use, the smart clause flatten(), this should provide the output as a list.
Hey Marc,
Thank you for the answer, if I understand correctly, you mean I should use this format when you say 2nd option with keys?
combinedFeatures: [ { "key": "INTASSET-4046" } , { "key": "INTASSET-4049" } ]
But this format deletes prevoius entries and does not add new ones?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @janez_m
An Asset field doesn't have an add option.
If you want to add options to an assets field, you will need to store this information first in a variable and then on the edit of the field the variable and the new option will need to be provided.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Marc - Devoteam,
Thank you. With the help of support I was able to construct a correct variable to combine the features and add them to the field. The format for variable I used was like this if it will help somebody in the future:
{{#triggerIssue.fields.customfield_10196}}"{{key}}"{{^last}},{{/last}},{{/triggerIssue.fields.customfield_10196}}{{#issue.fields.customfield_10196}}"{{key}}"{{^last}},{{/last}}{{/issue.fields.customfield_10196}}
Now it works and adds new values to the parent!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But there was an issue with this solution - it does not work for multiple values being copied.
The next solution looks like it finally has all the edge cases covered:
{{#triggerIssue.fields.customfield_10196}}"{{key}}"{{^last}},{{/last}}{{/triggerIssue.fields.customfield_10196}}{{#if(triggerIssue.fields.customfield_10196.size)}}{{#if(issue.fields.customfield_10196.size)}},{{/}}{{/}}{{#issue.fields.customfield_10196}}"{{key}}"{{^last}},{{/last}}{{/issue.fields.customfield_10196}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe I should add the the biggest issue are commas that are in the strings when there is no value in a field or only one value.. Usually all the parsed smart values had commas in them causing a not valid JSON error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This was solved with a replace function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#:~:text=remove(String).-,replace,-(String%20target%2C%20String
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.