Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Add (not replace) labels from blocking issue to blocked issue

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

@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:

image.png

2 answers

1 accepted

1 vote
Answer accepted
Curt Holley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

Am I missing something? Can't this be done as simply as:

Screenshot 2022-02-22 085657.png

you just have to make sure you select the "Add/remove" operation.

ar.png

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

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 :)

Like Curt Holley likes this
Curt Holley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

Yes @Stefan Salzl  I recall having a similar reaction 😲  upon finding the add/remove operation. 

Enjoy!! 

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

@Curt Holley hahaha......so funny..... can´t stop lauging =D

Like Curt Holley likes this
0 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

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:

Screen Shot 2022-02-21 at 1.12.03 AM.png

Let me know if this works, and if so, can you vote for this answer?

Thanks!

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

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:

image.png

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

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. :-}

Like # people like this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2022

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. :-}

Like Curt Holley likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events