Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using Scriptrunner to copy a field value from Epic field to Requirement/User Story and Sub-Tasks

Sasha Sun I'm New Here Sep 01, 2021

Hi all,

We have a custom dropdown field called "Project Group" for Epic, Requirement/User Story and its sub-tasks. Now, we have to manually this field value. 

I would like to achieve "Project Group" of Requirement/User Story could inherit the field value from Epic directly, also sub-tasks could inherit the field value from Requirement/User Story. 

I did found some similar posts and answers on community, but they do not work for my case.  As Requirement/User Story is actually not a real child tickets of Epic, it's the issue in Epic, please see below. Sub-tasks could be children tickets of Requirement/User Story or Epic. Epic and Requirement-User Story.png

Can anyone please help me writing up the script. Thanks in advance!





1 answer

Hi @Sasha Sun

For your requirement, you could try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager
def projectGroup = customFieldManager.getCustomFieldObjectsByName('Project Group').first()
def epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').first()
def projectGroupValue = issue.getCustomFieldValue(projectGroup)

def subTasks = [] as ArrayList<Issue>

if ( == 'Epic' && issue) {
def links = issueLinkManager.getOutwardLinks(
links.each {
def destinationIssue = it.destinationObject as MutableIssue
destinationIssue.setCustomFieldValue(projectGroup, projectGroupValue)
issueManager.updateIssue(loggedInUser, destinationIssue, EventDispatchOption.DO_NOT_DISPATCH,false)

destinationIssue.subTaskObjects.findAll {
} else if(issue.getCustomFieldValue(epicLink)) {
def links = issueLinkManager.getInwardLinks(
links.each {
issue.setCustomFieldValue(projectGroup, it.sourceObject.getCustomFieldValue(projectGroup) )
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH,false)
} else if(issue.isSubTask()) {

subTasks.each {
def subTask = it as MutableIssue
subTask.setCustomFieldValue(projectGroup, it.parentObject.getCustomFieldValue(projectGroup))
issueManager.updateIssue(loggedInUser, subTask, EventDispatchOption.DO_NOT_DISPATCH,false)

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

Below is a print screen of the listener configuration:-



What this code does is that if the Project Group field is updated in an Epic, all the issues in the epic, including the sub-tasks, will update the value according to the value set in the Epic.

Also, suppose any new issue or sub-task is created and is associated with the epic. In that case, the Project Group value in the new issue will automatically be set according to the value in the Epic.


I hope this helps to answer your question. :)


Thank you and Kind Regards,


Sasha Sun I'm New Here Sep 08, 2021

This is perfect!! Thank you so much!!!

Hi @Sasha Sun

Great to hear the solution worked for you. :)

Kindly accept the solution provided.


Thank you and Kind Regards,


Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Does this listener handles the case of removing Story from it's Epic?

The wanted result is null for the custom field.


Thank you,


Hi @dorin gez

To answer your question, the listener example provided above does not do what you are expecting.

It only updates a particular custom field value in all the issues and sub-tasks of an epic if that specific custom field's value is updated in the parent epic itself.

What you are expecting can be done but will require a different code and listener configuration.

Thank you and Kind Regards,


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

135 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you