Inherit Components from Epic to User Story, Epic link updated


Could somebody correct me with below script:

Create a user story, "Component" field should be empty. 
Update Epic Link for user story, Component field should be copied from Epic to User Story. I am user Script listener with "issue updated" Event.

I have below script, could any one correct this script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.util.ImportUtils

MutableIssue issue = (MutableIssue) event.issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()

// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {

// Get Custom Field as string (Epic Link)
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

// Get Custom Field Value as String
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
String EpicName = issue.getCustomFieldValue(epicLink);

// Get Epic from Issue
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue

// Get Component from Epic
def currentValue = epicIssue.getComponents()

// Set component to Story

1 answer


I did some similar things, but I never used the custom field Epic Link as it is not clear what kind of data type is in it. I guess that your "...getCustomFieldValue(...) as Issue" will for sure not work!

I used the link info instead to get the Epic issue:

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(event.issue.getId()).each {issueLink ->
    if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
        Issue epicIssue = issueLink.getSourceObject()

In addition, I think you should also save the changes in your issue:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser userId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue (userId, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

(not dispatching update events further on as you might get in an endless loop)


Hope this helps

Hi Marc,

Thank you for your help.

I am still having issue in getting this work. If you don't mind, could you please paste the paste the complete script.

Sorry for troubling you more and thank you in advance.



Hi Suresh,


The scrript is quite long and refers to a configuration (fields, workflows, ...) that is specific to our environment, so I think it is not very useful and will be difficult to understand.

Can you rather clarify what issues you still have ?


Suggest an answer

Log in or Sign up to answer
Community showcase
Published 7 hours ago in Statuspage

194 years of downtime: looking back on incident data from 2018

Statuspage customers logged more than 194 years of collective incidents in 2018. That’s a whopping 87% increase from the  104 years logged in 2017 , and we aren’t even through December yet....

19 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you