Copy subtask field to another parent field

Hi there,

 

im trying to find a solution for following usecase:

In case of a Defect we use Subtasks for Analysis, Execution and Verification. Each of the subtasks has a field "Description of Done" (as all other issuetypes too). I´d like to copy the values from Subtasks to parent fields and map them to the Fields "Description of Analysis", "Description of Execution", "Description of Verification".

 

What would you suggest?

 

 

bg,

Andy

2 answers

1 accepted

solved it myself...

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import java.sql.Timestamp

String copyFrom="customfield_10406"
String copyTo="customfield_10913"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
def parentIssue = (MutableIssue)issue.getParentObject()
def IssueManager = ComponentAccessor.getIssueManager();
def jac = ComponentAccessor.getJiraAuthenticationContext();
def cfObj= customFieldManager.getCustomFieldObject(copyFrom)
def valcfObj= issue.getCustomFieldValue(cfObj)
def cf2Update= customFieldManager.getCustomFieldObject(copyTo)
def valcf2Update = parentIssue.getCustomFieldValue(cf2Update)
def time=new Timestamp(new Date().time)
String txt_time=time.format('yyyy-MM-dd HH:mm')
if (valcf2Update == null){
    parentIssue.setCustomFieldValue(cf2Update,valcfObj)
    } else {
    parentIssue.setCustomFieldValue(cf2Update,txt_time + "\n" + valcfObj + "\n\n" + valcf2Update)   
 }
IssueManager.updateIssue(jac.getLoggedInUser(), parentIssue, EventDispatchOption.ISSUE_UPDATED, false);
0 vote

You're going to need

A little bit of thought on how to deal with clashes.  Say you have two subtasks with different values, do you just take the data from the last updated one, or do you set up the parent fields to accumulate values?  Do you de-duplicate, and so-on

Secondly, you've not specified when you want to do it, but I'd guess a post-function or maybe listener is the most likely place.

Finally, once you've made those decisions, the answer is that you'll need to find or write some code to do this.  I'd use the script runner as usual.

thx for your Reply!
for clarification: i use seperate Issuetypes for the Subtasks "Analyse", "Execution" and "Verification"
You´re right, i need this as a postfunction.
So every time a Subtask is done, the value of field "Description of done" shall be copied to the sorresponding field in the parent issue (Description of Analysis, Execution, Verification)
Because there could be more than one Analysis - Subtask, i Need to accumulate the values.
 
Is there an example for Script Runner (im just a beginner...)?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Service Desk

Wy are we still using email for Service Desk workflows?

...attest to the experience of an urgent approval that gets lost in the boss’s inbox and requires that special “Please Approve” email or text message. In an age where we have distributed teams...

104 views 0 2
Read article

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