[ScriptRunner] [Server/Data-Center] Copy Fields to Subtask

Dan Long May 9, 2022

I am trying to set Fix Version and Custom Field "Team Codes" when a sub-task is created.  I have an Issue of Type PTR and I go to More -> Create sub-task.   The PTR has Team Codes and Fix Version fields defined.   As a test, I am using the the example script from Script Runner with the single change of modifying List copyCustomFields = ["Team Codes"].  I threw some log.error("blah") to see where it was existing and it's inside this if-statement:

 

if (!parentIssueId || underlyingIssue) {
    // this is not a subtask, or issue already exists, so don't set default values
    return
} 
Because it's exiting early, it doesn't perform any of the copy of the fields.  I have the script-runner as a post-function in the create transition.  I also tried moving the function from the top of the post-functions to the bottom that didn't change anything (I didn't expect it to...).
Any ideas?

2 answers

1 accepted

0 votes
Answer accepted
Dan Long May 13, 2022

I found this post:

https://community.atlassian.com/t5/Adaptavist-questions/Copy-information-from-parent-issue-to-sub-task/qaq-p/1581004

Which lead me to this post:

https://library.adaptavist.com/entity/copy-field-value-from-parent-issue-to-sub-task-upon-creation.

This worked for me.  I needed to copy a custom field as well as system field, Fix Version/s.  

 

NOTE: ScriptRunner has a predefined Post-Function script called "Copy field values [ScriptRunner]" -- I couldn't get this to work properly; the log says that it runs without error but after the subtask creation, the field is empty/null, which is why I had to go the custom script route.

NOTE 2: There is also a free plugin that only copies custom fields not system fields, called Copy to Subtask Plugin. I also could not get this plug in to work for Custom Fields.  Creates a menu item Create Subtask - JCTS.

NOTE 3: Finally, JMWE (Copy field value from parent issue (JMWE plug-in)).  Also could not get it work for custom or system Fields.

0 votes
Andrea Pannitti
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.
May 9, 2022

Hi @Dan Long,

I think the best way to do this is by a postfunction on create in sub-task workflow.

Dan Long May 9, 2022

I guess I'm not sure what you mean? Can you give me more detailed steps? I made a copy current workflow then assigned that to the sub-task, but the post-functions are the same.

Suggest an answer

Log in or Sign up to answer