How to copy fields from parent issue to subtask and pre-populate fields on create sub-task screen?

RSP July 6, 2021

There are 3 fields (Start Date, End Date and Summery ) which I want to copy from parent issue to sub-task.

While creating sub-task, value of these fields need to populate on create sub-task screen.

How should I write Behavior for this requirement.

3 answers

1 accepted

1 vote
Answer accepted
Niranjan
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 6, 2021

Hi @RSP ,

If you are looking to copy the field value when a sub-task is created, you can add them as a post-function on create issue transition. 

JWME app offers a post-function "Copy field value from parent issue (JMWE app)".

Here is a script runner code - https://library.adaptavist.com/entity/copy-field-value-from-parent-issue-to-sub-task-upon-creation

Add this as the first post function on the Create step of a workflow

RSP July 6, 2021

Thank You

Like Niranjan likes this
Niranjan
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 6, 2021

@RSP  - Kindly accept the answer so that the post will be marked as SOLVED. Thanks and Good luck

RSP July 6, 2021

Hi @Niranjan , I found code to copy custom fields from parent issue to sub-task.

I have written behavior for same.

Like # people like this
Queenmary September 13, 2021

Hi RSP,

I am also looking for the same.

can you please share the behavior code which worked good for you

So that I can also achieve the same

Thanks
Queenmary

RSP September 14, 2021

.

RSP December 8, 2021

Hello  @Niranjan 

Can we copy system field value on subtask upon creation screen using behaviour

Regards,

RSP

Niranjan
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.
December 8, 2021

Hi @RSP ,

That is pretty much doable. You can add it as a postfunction ( of sub-task creation transition).

0 votes
Patricia Pattin June 30, 2022

Hi everyone 

 

I sure hope you can assist. And I am positive I am probably doing something simply wrong. But I cannot get this to copy fields from the parent to the sub-task on creating. Can someone look at my script

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.customfields.option.Option

import com.atlassian.jira.issue.fields.CustomField

import com.onresolve.jira.groovy.user.FieldBehaviours

import com.onresolve.jira.groovy.user.FormField

import groovy.transform.BaseScript

 

import java.sql.Timestamp

 

import static com.atlassian.jira.issue.IssueFieldConstants.*

 

@BaseScript FieldBehaviours fieldBehaviours

 

FormField field = getFieldById(getFieldChanged())

FormField parent = getFieldById("parentIssueId")

Long parentIssueId = parent.getFormValue() as Long

 

 

if (!parentIssueId || underlyingIssue) {

    // this is not a subtask, or the issue has already been created and we don't need default values

    return

}

 

def issueManager = ComponentAccessor.getIssueManager()

def parentIssue = issueManager.getIssueObject(parentIssueId)

def customFieldManager = ComponentAccessor.getCustomFieldManager()

 

// REMOVE OR MODIFY THE SETTING OF THESE FIELDS AS NECESSARY

getFieldById(SUMMARY).setFormValue(parentIssue.summary)

getFieldById(PRIORITY).setFormValue(parentIssue.getPriority().id)

 

 

//getFieldById(SUB PROJECT).setFormValue(parentIssue.Sub Project*.id)

//getFieldById(TARGET TYPE).setFormValue(parentIssue.Target Type*.id)

//getFieldById(COMPONENT/S).setFormValue(parentIssue.Component/s*.id)

//getFieldById(TEST ISSUE TYPE).setFormValue(parentIssue.Test Issue Type*.id)

//getFieldById(SOC NAME).setFormValue(parentIssue.SoC Name*.id)

//getFieldById(SOC REVISION).setFormValue(parentIssue.SoC Revision*.id)

//getFieldById(SOFTWARE APPLICATION).setFormValue(parentIssue.Software Application*.id)

//getFieldById(DESCRIPTION).setFormValue(parentIssue.description)

//getFieldById(LABELS).setFormValue(parentIssue.labels)

Kayla Smith July 1, 2022

Hi Patricia. Do you have Automation for Jira installed in your system? This can be accomplished using that plugin much more easily

Patricia Pattin July 1, 2022

Unfortunately, I do not. However, I didn't think it could do it on actual create only when you click create?

Like Sayan Kaiser likes this
0 votes
yundong.li February 15, 2022

@RSP 

Hi RSP, 

I am also looking for the same.

can you please share the behavior code which worked good for you.

I use the JMWE (Copy field value from parent issue (JMWE app)) ,it can copy fields from parent fields after created the subtask, not before.

I also use Create Subtask - JCTS ,but this plug can not copy the system fields values.

 

Neither of these are ideal.
Is there a better way to automatically integrate the field values of the parent task when we create a subtask?

Suggest an answer

Log in or Sign up to answer