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

Script Runner - Copy Custom Field Value from Parent When Sub-Task is Created

When Sub-Tasks are created from a Story, I would like the parent Story's custom field value to be copied to the Sub-Task's custom field value. For example: I have a field named "Client" and I want the value to appear within the Sub-Task's "Client" field after the Sub-Task is created.

I am not interested in a paid add-on for JIRA and would like to use Script Runner instead.

I have tried to test my script below using the console, but am getting errors related to "issue" and "transientVars" not being understood.

Thank you for your help in advance!

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()

CustomField customField_name = customFieldManager.getCustomFieldObjectByName('Client')

def parentMyFieldValue = transientVars["issue"].getCustomFieldValue(customField_name)
issue.setCustomFieldValue(customField_name, parentMyFieldValue)

2 answers

1 accepted

2 votes
Answer accepted


If you run the script in script console, you have to use an issue as an example. Its not there in the context when you run it from the console.

For testing purposes, use below line in the code.

issue = ComponentManager.getInstance().getIssueManager().getIssueObject("TEST-1234")

If you put the script in post function, you might not get error for this.

Option will also be to do use the JIRA Suite Utilities Plugin, its free.

The plugin provides the post-function to copy value from other field, from parent to sub-task. You can add this post-function in the create transition for the sub-task.


As Vijay says... if you test this as a workflow action it should work.

Note that in this scenario, issue refers to the new issue being created, and transientVars["issue"] refers to the parent or source issue.

Thank you! I decided to try out the JIRA Suite Utilities Plugin and it did just what I needed. I created a post function for each field that I wanted to copy from the parent using the "Copy Value From Other Field" function.

JSU will not do this in Jira Cloud for the "Accounts" field from Tempo.  The JSU post-function does not include the ability to run the post-function as the transitioning user vs the addon-user.

Hoping that will get fixed soon!

Hi Alan

We're still working on getting all the features on Server to Cloud. However, as we have to basically re-create the App on a different platform, this is taking a while.

Stay tuned for updates!

0 votes
Paul Stallworth Community Leader Mar 16, 2016

Is this answer still correct for JIRA 7 API?  I had to change to use ComponentAccessor as there is no longer a getCustomFieldManager() in ComponentManager.  Also, this line statement throws an error 

def parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)

could not find java.lang.Object#getCustomFieldValue.  Do I need to cast transientVars["issue"] to something more appropriate?

What is the context here, are you using one of the built-in scripts, or is this completely custom?

Yes, that API has changed, you can read what you need to do here:

Paul Stallworth Community Leader Mar 18, 2016

Thanks for pointing me to the JIRA 7 page.


I initially tried to drop in the code from above as I have the same need as this question.  I got an error when trying to use transientVars so I poked around and came up with the code below.  It works but I'm not sure if it is the best way now so if you have any critiques I'll take them.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10603')
def parentMyFieldValue = issue.parentObject.getCustomFieldValue(field)
def changeHolder = new DefaultIssueChangeHolder();
field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field), parentMyFieldValue),changeHolder);

Paul, do you have any idea  to apply above code for fix version copy ?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

314 views 1 3
Join discussion

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