Our goal is to have a listener that will run and ensure that if the FixVersion of a Story is updated, that it will trickle down the update to the associated subtasks.
I have made this change for a custom field we are using called "Team" as follows. When running, it will copy the Team field to its subtasks when updated. For some reason I can't get the same script to work for FixVersion - can someone help me?
Here is my script in use for event: issue updated for our custom field = 'Team' (adapted from Adaptavist documentation):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Team"}
if (change) {
log.debug "Value changed from ${change.oldstring} to ${change.newstring}"
// your actions if the field has changed
def subtasks = event.issue.getSubTaskObjects()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Team")
if (subtasks){
subtasks.each {it ->
def options = ComponentAccessor.getOptionsManager().getOptions(customField.getRelevantConfig(it))
((MutableIssue) it).setCustomFieldValue(customField, options.find {it.value == change.newstring})
ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}
Thanks in advance.