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
Hi @Lakshmi CH
For your requirement, you will need to use the Post-Function for the Create transition as shown in the screenshots below:-
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:-
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:-
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:-
2. Below is a screenshot of the Story with no labels in it.
3. Below is a screenshot of the Sub-type issue that has copied the Epic labels.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.