I have a task: copy components from parent to sub-task when sub-task's parent changed.
Example:
I have Parent 1 with component ABC and its sub-task 1 with the same component ABC and Parent 2 with component DEF. I move sub-task 1 to Parent 2, so sub-task 1's component should change to DEF.
In listeners I usually use event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == 'fieldName' } so I wonder if there is a field in sub-tasks that contains parent issue value so I can check if this field changed.
If no, is there another way to implement it?
Found the field name myself :) it is "Parent Issue"
Maybe it will help someone, the code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
// current issue
def issue = event.issue as MutableIssue
if (issue.getIssueType().getName() == "Sub-task") {
// the name of the field to check
final String fieldName = "Parent Issue"
// user that will make updates
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// check if a right field was updated
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find
{it.field == fieldName}
if (change) {
def issueManager = ComponentAccessor.getIssueManager()
// get components of parent issue
def components = issue.getParentObject().getComponents()
issue.setComponent(components)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
} else return
} else return
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.