The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can I copy a field value from sub-task to the parent issue

miller j
Contributor
October 24, 2017

Hi,

I am looking for a method to update a parent issue custom field with data from a sub-task when I transition a sub-task. (perhaps some post-function or a script listener)

For example:

Each of the Subtasks will have a Multi User Picker field.

If Subtask-1 has values User-1, User-2, Subtask-2 has values User-2, User-3 then the parent custom field should have values of User-1, User-2, User-3

 

Is this possible using only the script runner plugin?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Daniel Yelamos [Adaptavist]
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 Champions.
November 21, 2017

Yes it is. You would use a script post function on your desired transition within your subtask. The code would do the following:

Get parent of the issue of the issue like so

def parentIssue = issue.getParentObject()

After getting the parent, you can fetch the values of your fields and set them easily. There are multiple questions on the community about how to set fields and get their value. If you have problems let me know and I can craft the whole thing, but that's going to take me some time.

Cheers!

Dyelamos

Thanos Batagiannis _Adaptavist_
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 Champions.
November 21, 2017

In addition to what Daniel said, the script will look something like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issue = issue as MutableIssue

if (! issue.isSubTask()) {
return
}

def parentIssue = issue.parentObject
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("MultiUserPickerA")

def listOfUsers = parentIssue.subTaskObjects?.collect {
it.getCustomFieldValue(cf)
}?.flatten()?.unique() - null

log.debug "list of user to set are $listOfUsers"

def changeHolder = new DefaultIssueChangeHolder()
cf.updateValue(null, parentIssue, new ModifiedValue(parentIssue.getCustomFieldValue(cf), listOfUsers),changeHolder)