Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements


  • Give kudos
  • My kudos


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need a script to copy the value of a user picker field from parent to sub task in script runner

Need a script to copy the value of a user picker field from parent to sub task in script runner

2 answers

1 accepted

2 votes
Answer accepted

Here it is!

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomField field = customFieldManager.getCustomFieldObject("customfield_15117")

Collection<Issue> subTasks = issue.getSubTaskObjects()
subTasks.each { subTask ->
MutableIssue mutableIssue = issueManager.getIssueByKeyIgnoreCase(subTask.getKey().toString())
ApplicationUser appUser = ComponentAccessor.getUserManager().getUserByName("sysadmin")
mutableIssue.setCustomFieldValue(field, issue.getCustomFieldValue(field))
issueManager.updateIssue(appUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)


0 votes
Tarun Sapra Community Leader Feb 27, 2018

Just to add to the good answer provided by @Mahesh_S

In the final line of code, I would use

issueManager.updateIssue(appUser, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)

instead of  

issueManager.updateIssue(appUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)

Because as per docs

Issue updateIssue(ApplicationUser user,
                  MutableIssue issue,
                  EventDispatchOption eventDispatchOption,
                  boolean sendMail)

This method will store the provided issue to the JIRA datastore.

The issue will be saved and re-indexed unless EventDispatchOption.DO_NOT_DISPATCH is specified. This method performs no permission checks.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

75 views 1 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you