Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Scriptrunner Listener to Update Subtask Component Edited

Hi community, I'm in need of some help. I'm looking to use Scriptrunner to create a script to update the component field of a subtask or subtasks when the component field of the parent issue is updated or when a new subtask is created. 

I am new to Scriptrunner and have managed to get this working for other fields (FixVersion and Labels) but can not seem to figure this out for Components. 

Any help would be so greatly appreciated. Here is what I have scripted that isn't working. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent

IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)

Issue updatedIssue = event.getIssue()
Collection<ProjectComponent> components = new ArrayList<ProjectComponent>()
components = updatedIssue.getComponents()
Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
subTasks.each {
if (it instanceof MutableIssue) {
((MutableIssue) it).setComponentObjects(components)
issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)

1 answer

0 votes
Leonard Chew Community Leader Feb 03, 2020

Does it need to be scriptrunner? - I think this use case could be easily configured with "Elements Copy and Sync".

If it needs to be Scriptrunner then you'd need:

  • A Postfunction (on the create issue step) for the Sub-Task
  • A Listener (on edit on the parent issue) that synchronizes the components 

To get your script working, try these snippets:

Get all components of parent issue:

def components = parentIssue.getComponents()

then within the subtask-loop:



I have not tested the code. Hope it works.

Thanks for the mention @Leonard Chew 

@William GarrettIf you want to see how synchronization of fields works with Elements Copy & Sync, check out this page of the documentation:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

182 views 3 19
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