Scriptrunner Listener to Update Subtask Component

William Garrett February 3, 2020

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
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.
February 3, 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:


subTaskIssue.setComponent(components)

 

I have not tested the code. Hope it works.

Laura Campbell _Seibert Media_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2020

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:

https://doc.elements-apps.com/elements-copy-and-sync/latest/?contentKey=synchronisation/

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events