Script runner Create Subtask built-in script postfunction

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

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

1 vote
Answer accepted
Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

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

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

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) ..???

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2013

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

2 votes
Brannon Fay January 15, 2014

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

1 vote
Brannon Fay January 15, 2014

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 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2015
0 votes
Brian Bishop
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2015

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?

0 votes
TSO Logic Admin February 14, 2014

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

0 votes
TSO Logic Admin February 4, 2014

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

0 votes
TSO Logic Admin February 3, 2014

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2014

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

0 votes
Bartosz Burchard January 15, 2014

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);
0 votes
Bartosz Burchard January 14, 2014

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)

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

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.

Chris Kent
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2014

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?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2014

Can you create a ticket including the stack trace?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2014

Seems to be the same as this issue below: https://jamieechlin.atlassian.net/browse/GRV-409- looking at that now.

Chris Kent
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

Yes agreed, same issue.

Thanks

Suggest an answer

Log in or Sign up to answer