You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hey everyone, im trying to create a rule for copy and remove labels to child issues.
Then any changes to the labels must be copied to child issues.
Would anyone have an example?
Hi @Rodrigo Baccaro Kazlauskas
Would you please clarify your use case? Do you want to
Kind regards,
Bill
Hi @Bill Sheboy
Thakns for your reply.
I didnt think about the option 2, but this option will be better. Could you help me how to setup this 2nd option?
King regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the more complicated option, as you first must remove the previous labels the parent used, and then add the current values. Both of these use the {{changelog}} smart value.
For example, this rule would be triggered on a parent epic's labels changing:
This one grabs the prior values (fromString) for the triggering epic, and splits them up so they can be removed from the child issue. Similarly the new values (toString) are then added. I believe this must be done in separate steps, with the Re-fetch in the middle, to avoid a collision.
I recommend trying this in either a test project or with test issues first. If it does not work as you want, you can switch to Case 1 (simple replacement), as that is much simpler.
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.
Nope...my example rule that I wrote last year has stopped working since then. Let me experiment using a JSON edit instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I rebuilt my example rule for this :^)
I recommend testing to confirm it works as you want.
This uses the change log, created variables and JSON, dynamically built, to first remove the old labels and then to add the new ones. To learn about this method, please take a look at the linked documentation above.
{
"update": {
"labels": [
{{#if(exists(varRemoveLabels))}}{{varRemoveLabels}},{{/}}
{{varAddLabels}}
]
}
}
How it works...
To pass down the epic changes to labels and preserve and different values in the child issues (e.g. stories) we need to remove the old (before) epic labels and then add the new (after) epic labels. Ideally, we want to do this in one step to avoid repeated changes to the same issue.
When an issue changes, information is captured in the change log, including the before and after values. For labels, the changes are stored as a list of values with spaces between each label change. So we can capture the before values with {{#changelog.labels}}{{fromString}}{{/}} and then split them with the embedded spaces. We can do the same thing to get the after values with {{toString}}
When using the JSON edits, we need to use the specific format which allows both adding and removing changes to do this in one step. For labels this looks like this:
{
"update": {
"labels": [
{
"remove": "Label1"
},
{
"add": "Label2"
}
]
}
}
The wrinkle for synching labels is we do not know how many will be added or removed, and so we dynamically build the bolded sections above for the {{varAddLabels}} and {{varRemoveLabels}}
The final piece is the "remove" section could be empty, and so that conditional logic test helps prevent a stray comma from breaking things.
Give it a try and please let me know how it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
Thanks for your solution, I've tried to implement it however I keep getting the following error code when I'm adding the following section
I should mention I am using a company-managed project on Jira Cloud. Do you have any idea why this error is appearing and what JSON commands I could/should use to avoid this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Akanksha Saha -- Welcome to the Atlassian Community!
That messages seems to indicate what it says: a permissions problem.
What is the rule actor for your rule (under details at the top of the rule edit)? And if it is the default of the "Automation for Jira" user, did someone change the permissions for that user and the project?
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Bill Sheboy
I am trying to use what you provided in this post to create an automation that will add a single select custom field value to the Labels of the same issue, but remove the old value. For example, if the custom field has value 1 that was originally copied over to labels and a user selects value 2, the automation would then remove value 1 and add value 2 in the labels instead. I am on a Data Center and the create variable is not available in DC as yet.
Would you be able to help out this a suggestion for such a situation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Adam Ziecik
First thing: I am using Jira Cloud and so I cannot test my suggestions on this one...
Next, it appears Atlassian has started work on adding the Create Variable action to the Server/Data Center version of automation rules. You can follow this suggestion for progress updates: https://jira.atlassian.com/browse/JIRAAUTOSERVER-384
Back to your question...I wonder if you could do this in two steps:
The part I do not know for Server/Data Center: does the content of the changelog remain stable after the re-fetch action? If it does, this will probably work.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy - thank you for getting back to me :)
I was thinking along these lines, but please could you support with how to get the proposed by you:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please take a look earlier in this thread where the variables are created to do this: varRemoveLabels and varAddLabels. Instead of creating variables, you would use the expressions directly in two different issue updates with JSON, with the issue re-fetch between them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy - I did have a look and tried to follow it, but I got the following error. Probably because the JSONs I tired are wrong. Please, could you help with the JSONs for both remove and add labels ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would you please post images of your complete rule, including the details of the issue edits with JSON, and of the audit log details showing the rule execution? Those may provide context for what you are seeing.
The JSON I noted earlier worked for the original question and for Jira Cloud, so something may be different for your scenario.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy - thank you again for getting back to me.
I have no experience writing JSON. I tried to do the following:
For removing the label:
{
"update": {
"labels": [
{{varRemoveLabels}}
]
}
}
For adding the label:
{
"update": {
"labels": [
{{varAddLabels}}
]
}
}
I get the following error in the audit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information, @Adam Ziecik
As you noted you are using the Server/Data Center version, there are no created variables and so that syntax cannot work. Specifically, you cannot use {{varRemoveLabels}} and {{varAddLabels}}
Instead you need to replace the created variables in the JSON expression with what was used to create them. Please try that, and then post an image of your complete rule so we can confirm what you are trying. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have one for removing the label copied from the custom field and another one for adding it, with the re-fetch in the middle like in the print screen I posted before. However, I guess, it would need to know what was the old value of the custom field to be removed rather than removing and adding the current custom field value as otherwise it does not make any sense.
Do you think you could guide me how to writhe such JSON?
{
"update": {
"labels": [
{
"remove": "{{issue.customfield_10874.value}}"
}]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would substitute in the expression I noted earlier. For example, the one for the remove would be this:
{{#changelog.labels}}{{#fromString.split(" ")}}{ "remove": "{{.}}" } {{^last}}, {{/}}{{/}}{{/}}
And then inserted into the JSON update would be:
{
"update": {
"labels": [
{{#changelog.labels}}{{#fromString.split(" ")}}{ "remove": "{{.}}" } {{^last}}, {{/}}{{/}}{{/}}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy - thank you very much for this.
I have used it and then replaced the "remove" with "add", but I received the following error message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There appears to be something different with your rule, or with Jira Data Center, in this automation scenario. Let's try this step by step...
Please replace your edit with a write to the audit log for just the remove expression value:
REMOVE: {{#changelog.labels}}{{#fromString.split(" ")}}{ "remove": "{{.}}" } {{^last}}, {{/}}{{/}}{{/}}
Then add another write to the log with the full list of labels:
ALL: {{issue.labels}}
Then run your rule and post the audit log to show what happened.
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.
Please use the Log action to write things to the audit log. This helps with diagnosing problems in rules and to confirm rule progress.
https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Log-action
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.
***Assuming the child issues will always have the same labels as the parent:
1. Create the Trigger: "Field value changed" (Labels)
2. Create a "Branch rule / related issues":
issuekey in portfolioChildIssuesOf{{issue.key}}
3. Create an "Edit issues" action
If the child issues may have different labels than the parent, then you will have to parse the changelog.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Grace Shaw -- Welcome to the Atlassian Community!
My understanding is the function portfolioChildIssueOf() is only available with Advanced Roadmaps, provided with a Premium Jira license. And the person who originally asked this question is not on that license level.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy — I did not realize these details (that portfolioChildIssueOf is an Advanced Roadmaps-only feature, and the user's license level). Your answer is more robust anyway. Thanks for the feedback!
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.