Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy the "Epic" label field value to its Story Subtasks's labels field

Lakshmi CH
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.
January 12, 2023

Hi Team,

 I was trying to copy the "Epic" label field value to its Story Subtasks's labels field. I don't want to copy that "Label" field value to Story, I am looking for the solution to copy directly from Epic -> Sub-task (it should not copy to Subtask parent ticket "Story).

Jira Version : 8.22.6

Addons : JMWE, script runner , and JSU

 

-Sara

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
January 24, 2023

Hi @Lakshmi CH 

For your requirement, you will need to use the Post-Function for the Create transition as shown in the screenshots below:-

transition1.png

transition2.png

You will need to include a new Post-Function. From here, you will need to select the custom script post-function [ScriptRunner] as shown in the screenshot below:-

transition3.png

Once you have selected it, you must include the custom code.

Below is the working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def customFieldManager = ComponentAccessor.customFieldManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.issueManager
def labelManager = ComponentAccessor.getComponent(LabelManager)
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()

if (issue.isSubTask()) {
def parentIssue = issue.parentObject
def epicLinkValue = parentIssue.getCustomFieldValue(epicLink).toString()
def epicIssue = issueManager.getIssueByCurrentKey(epicLinkValue)
def newLabels = [] as Set<String>
epicIssue.labels.findAll {
newLabels.addAll(it.label)
}
labelManager.setLabels(loggedInUser, issue.id, newLabels, false, false)
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Post-Function configuration:-

config_1.png

Below are a few test screenshots for your reference:-

1. A sample epic is created with the Epic with some sample labels as shown in the screenshot below:-

test1.png

2. Below is a screenshot of the Story with no labels in it.

test2.png

3. Below is a screenshot of the Sub-type issue that has copied the Epic labels.test3.png

 

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Sangram Darole January 3, 2024

i am trying to copy field values from Epic to Issues in Epic.  but it is not working. Is it working for anybody through the Scriptrunner / JSU

Suggest an answer

Log in or Sign up to answer