Propagate a custom label from subtasks to parent

Craig Easton September 22, 2022

I have a custom field that is of type label. Any time this field is changed on a subtask, I would like to overwrite the parents field with all the labels from its children tasks.

I have the easy part done below, now I need to replace "bugfix","blitz_test" with the syntax to get each label from all tasks siblings and add them to the parent.

 

rule.jpg

Thank you

3 answers

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.
September 22, 2022

Hi @Craig Easton 

To add all of the labels from all of the subtasks, you first need to get all of those labels.

One way to do that is with the Lookup Issues action:

  • action: using JQL which finds all of the sibling subtasks from the trigger issue, load up the Lookup Issues
    • parent = {{triggerIssue.parent}} AND issueType = subtask
  • branch to and edit the parent, using the combined labels list, getting the distinct values
    • {{lookupIssues.yourCustomFieldName.distinct.asJsonStringArray}}

Kind regards,
Bill

Craig Easton September 23, 2022

Hi @Bill Sheboy thank you very much! With your guidance I almost got the exact result I'm looking for. Except that the labels are being added with [ ] around them. I tried to substitute asJsonStringArray with asJsonString but I get errors.

Is there an easy way to remove the [ ] from the labels?

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.
September 23, 2022

Hmmm...the question is, what is adding them: the initial parsing or the later conversion to the JSON string array.

Let's assume it is the first one, and so use this as the source to try removing them:

{{lookupIssues.yourCustomFieldName.remove("[").remove("]").distinct.asJsonStringArray}}

Craig Easton September 23, 2022

Thanks again Bill, it looks like it was latter. I was able to address it removing all the square brackets after array and then wrapping it all in a single [ ] to get my desired outcome:
[{{lookupIssues.yourCustomFieldName.distinct.asJsonStringArray.remove("[").remove("]")}}]

Like # people like this
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.
September 23, 2022

Well done, Craig!

Like Stefan Salzl likes this
0 votes
Craig Easton September 22, 2022

.

0 votes
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.
September 22, 2022

Hi @Craig Easton and welcome to the community,

I´m not quite sure if I can follow correctly. What exactly does "all tasks siblings" mean?

So to clarify:
Am I assuming right that when Issue-A is the parent and Issue-B is the subtask --> when Issue-B field Teams is updated then labels from Issue-B should be written to Issue-A (parent) and overwrite eventually already existing labels there?

 

If so the following does the work:
image.png

 

If your customfield is not available in the dropdown this advanced edit in JSON would should work:

 

{
"fields": {
"customfield_10062":
{{triggerIssue.customfield_10062.asJsonStringArray}}
}

 

BTW: you can find an excellent docu of advanced JSON edit here:
https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Adding-labels

 

Please let me know if this was helpful.

Best
Stefan

Craig Easton September 22, 2022

Hi @Stefan Salzl thanks for the response.

Yes in your case, what you describe does work. However it fails in the following scenario:

Issue A - Parent

Issue B - Subtask of Issue A

Issue C - Subtask of Issue A

Add Team-B to Issue B -> Issue A Team = Team-B

Add Team-C to Issue C -> Issue A Team = Team-C

What I would like the result to be is that Issue A has Team = Team-B, Team-C

As well, if I removed Team-C from Issue C I would like Issue A to be reflected with Team = Team-B.

I hope that makes sense and why the 'copy x from trigger issue' didn't work for me even though my custom field is listed there.

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.
September 22, 2022

If Issue-B is subtask of Issue-A how can Issue-C be a subtask of Issue-B? Logically this would mean Issue-C is a subtask of a subtask. 

Craig Easton September 22, 2022

Sorry that was a mistake, I fixed it.

Issues B and C are subtasks of Issue A.

Suggest an answer

Log in or Sign up to answer