Copying Components and Labels from issue in new issue via Automation for Jira
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
An admin may want to copy the Components values and the Labels value from an issue into a newly created issue using the Create a new issue action on Automation for Jira. This article will show the smart value used for this and the conditions for this to work.
While this article is a highly customized approach its idea is to show another option to handle Smart Values by using JSON's concat function.
Keep in mind this is a work in progress prone to change depending on feedback.
Solution
Create your Automation Rule and configure the conditions to trigger the rule.
Add a Create a new issue action.
Fill in the fields you'd like on your new issue. Keep in mind the
Additional fields information we'll add overwrites anything you configure by going Choose fields to set > Labels.
Add the script of your choice below to the Additional fields text field:
Version A: Will not work if either the Components or the Labels field from the trigger issue are empty:
1
2
3
4
5
{
"fields": {
"labels": {{issue.labels.asJsonStringArray.concat(issue.components.name.asJsonStringArray).replace("][",",")}}
}
}
Version B: Will work even if one of them is empty. The replace operations are meant to eliminate JSON parsing errors as a consequence of the previous replace command:
1
2
3
4
5
{
"fields": {
"labels": {{issue.labels.asJsonStringArray.concat(issue.components.name.asJsonStringArray).replace("][",",").replace("\",]","\"]").replace("[,\"","[\"")}}
}
}
Info:
If you attempt a similar action to Edit Issues instead of Create a New Issue, you might change the issue into triggerissue on the smart value but keep in mind this will overwrite pre-existing labels on the edited issue.
Warning
If you start having issues with highly customized smart-value based rules like the one proposed on this article for specific conditions such as both the values being null you may create a condition and lead the rule do a different path in that scenario to ensure the rule has no gaps.
Was this helpful?