@Stefan Salzl had an interesting question as part of this discussion that I think I figured out the answer to.
Stefan's post:
Description of the behaviour:
I want to add more than 1 labels from one issue to another one (eg. from parent to child) whereas the let´s say the child already got 2 labels and the parent has 2 different labels.
I tried to update a linked issue´s label field as follows:
{
"update": {
"labels": [
{
"add": {{destinationIssue.labels.asJsonStringArray}}
}
]
}
}
but audit log output says looks like:
Am I missing something? Can't this be done as simply as:
you just have to make sure you select the "Add/remove" operation.
Hooooly moly..... :o :o how could I oversee this option??? OOOOMG......
Thank you very much @Curt Holley (even if I invested the whole evening in trying to find a solution for this haha)
Well....learned a lot. therefore: it´s worth it.
Thanks guys for that great solution and lesson :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes @Stefan Salzl I recall having a similar reaction 😲 upon finding the add/remove operation.
Enjoy!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Curt Holley hahaha......so funny..... can´t stop lauging =D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So as I mentioned in the other post, the error you got is because the "add" function can only take a string, not an array.
But after solving Dane's issue with a bunch of ugly Smart Value JSON hackery, I realized your problem wouldn't be much harder. It requires a temporary variable, because once we branch to the Destination issue, we apparently can't access the original issue's field values.
Basically we set a Smart value variable originalLabels (from the blocking issue):
{{issue.labels.asJsonStringArray.replace("[","").replace("]",",")}}
And then we Branch to the Destination issue (what's being blocked) and edit using More options -> Additional fields:
{
"fields": {
"labels": {{originalLabels.concat(destinationIssue.labels.asJsonStringArray.replace("[","").replace("]","")).split(",").asJsonArray}}
}
}
}
So it ends up looking like this:
Let me know if this works, and if so, can you vote for this answer?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
uff.....a lot of things for me to learn from this example :) Haven´t been using smart value functions but will definitly take some deeper insights to understand what is possible with replace, split, etc.... :o :o
unfortunately the solution doesn´t work. See my audit log:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AH, I think I forgot to take into account this case:
* If the blocking issue (originalLabels) does not have any labels, then I should not include a comma.
Basically I ended up it trying to update with this invalid JSON for labels:
"labels": [,"childlabel1","childlabel2"]
(Note the extra leading comma.)
Ugh.... I think this can be fixed with some conditional array trickery or by adding a condition to skip the edit in case the blocking issue has no labels, but @Curt Holley has already provided a much. better. answer.
I'm gonna take a nap. :-}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I lied. :-}
I couldn't help myself. Here's the corrected JSON:
{
"fields": {
"labels": [
{{#if(not(triggerIssue.labels.isEmpty))}}
{{#triggerIssue.labels}}"{{.}}"{{^last}},{{/}}{{/}},
{{#destinationIssue.labels}}"{{.}}"{{^last}},{{/}}{{/}}
{{/}}
{{#if(triggerIssue.labels.isEmpty)}}
{{#destinationIssue.labels}}"{{.}}"{{^last}},{{/}}{{/}}
{{/}}
]
}
}
And the originalLabels variable is no longer required.
Obviously this is overly-complicating things, but I'm putting this here in case anybody else has to do something a little trickier with conditionals in JSON.
It's not quite as much of a headache as I initially feared.
One thing I thought of - if a blocking linked issue is unlinked, I don't know if you want to remove its labels from the blocked issue, but if so, you'd need another rule.
Additionally, you'd want to make sure that those labels in any other blocking tickets.
Yay, more conditions. :-}
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.