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

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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)

This widget could not be displayed.

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

This widget could not be displayed.

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)

This widget could not be displayed.

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);
This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

137 views 2 0
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