Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Mahesh S
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.
Feb 27, 2018

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)
}

 Cheers! 

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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.

TAGS
AUG Leaders

Atlassian Community Events