Script runner Create Subtask built-in script postfunction

I would like to use this script (https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Createasub-task) 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

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)
issue.setSummary(val_1)

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

Hope that helps

Cheers

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.

Bartosz,

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);

Cheers,

Brannon

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)

0 vote

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: https://jamieechlin.atlassian.net/browse/GRV-409- looking at that now.

Yes agreed, same issue.

Thanks

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)

issue.setDescription(parentMyFieldValue)

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,

Johnny

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?

-Johnny

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: https://jamieechlin.atlassian.net/i#browse/GRV-409

-Johnny

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,224 views 14 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot