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)
}
}
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:
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.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.