Script runner Create Subtask built-in script postfunction

I would like to use this script ( to create a subtask and copy fields from the parent to the subtask, eventually modifying some (like the subtask summary to be "Prefix - parent summary" for instance).

Is this possible or it only accepts literal values? If possible how do I reference the parent and subtasks issues in the postfunction?

Thanks in advance!

11 answers

1 accepted

1 vote
Accepted answer

Hi there,

it's possible to do the thing that you want.

If you want the summary of child task to be "Prefix - {parent summary}" in your postfunction setting you have to add the following in Additional issue actions field

issue.summary = 'Prefix ' + issue.getSummary()

If you have custom fields in your parent issue and you want to use the values in subtask you have first to create the custom field object. You can add the following in Additional issue actions field

def cf_1 = customFieldManager.getCustomFieldObjectByName('customfield_name')
val_1 = 'Test ' + issue.getCustomFieldValue(cf_1)

Be careful to have the subtask issue type in your custom field configuration.

Hope that helps


Thanks, this is what I needed.

Only one question: issue is a reference to the parent , to the subtask or to both (since it's in both sides of the assignment) ..???

issue is a reference to the new issue, in this case the subtask.


As Jamie said, issue refers to the sub-task. To reference the parent object you can go to it directly using transientVars["issue"].<field>

Here is an example:

issue.assignee == transientVars["issue"].assignee;
issue.description == null;
issue.setSummary("Unit Test - " + transientVars["issue"].key);



Hi Bartosz,

I haven't tried (that I recall) but it should work as you have above with the change noted:

cfParent = customFieldManager.getCustomFieldObjectByName('CUSTOM_FIELD_ID')
parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)

All fields are by default copied from the parent issue (where the issue type association is valid). To set custom fields to custom values you need to do more or less as Kostas says.

There's no restriction to text fields.

Hi Jamie,

I am seeing errors regarding the copy of all parent fields. We have JIRA Agile and the Epic Link field is copied from a story to a subtask. The Epic Link field is not valid for subtasks and is throwing errors.

Is there any way to fix this problem?

Can you create a ticket including the stack trace?

Seems to be the same as this issue below: looking at that now.

Yes agreed, same issue.


It doesn't work for me because it doesn't get values from parent issue.

I have tried to get some informations from parent but I received 'null' when I have called getParentObject() due it was called from a sub-task in post-function during creation.

parent = issue.getParentObject()

cfParent = customFieldManager.getCustomFieldObjectByName('CUSTOM_FIELD_ID')

parentMyFieldValue = parent.getCustomFieldValue(cfParent)


Thanks Brannon.

It works.

One more question. Is this a way to get customfields value from parent? I have some problems with that and I don't know why yet.

For instance:

issue.setSummary("Unit Test - " + transientVars["issue"].customfield-10912);

Hello Jamie,

Re: inheriting, how can we control that? And to what granularity? Or is this a matter of explicitly undoing all the copying

In particular, we noticed that the subtasks are inheriting the Description field from the parent issue. We would like the subtasks _not_ to inherit anything from the parent.

Thank you,


It inherits everything - you can unset what you don't need in the "additional code" section.

Hi Jamie, Thank you for the quick response!

Could you please clarify "everything"? Or can we see the source code so we can determine for ourselves?


Hi Jamie,

I believe there is a bug in the code that creates subtasks. Looking at your source, you have a parameter called "SKIP_EPIC_LINKS". But it looks like that does not get passed in the call from CreateSubTask to AbstractCloneIssue.

Hence my auto-created subtasks have Epic Link values. The Jira GUI explicitly stops the user from editing that field (only on subtasks) because it knows it should not be there!

I have created a ticket:


I'm trying to do something similar with the clone + link builtin script.  I simply want to change the security level of the newly created issue.


But its tough to get a handle on that new issue.


log.debug("DBG: issue key is " + transientVars["sourceIssue"].key)


is causing a null pointer exception.  Is there some other way to access the new, auto-created, cloned and linked issue?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,180 views 5 10
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