Using a Scriptrunner Listener to keep FixVersions in sync

Melinda Atkinson
Contributor
December 9, 2018

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.

1 answer

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 9, 2018

Hi,

Can you also show the code you tried for "fix version"?

Melinda Atkinson
Contributor
December 9, 2018

It's the same as above but with FixVersion in the place of 'Team'.  but I realize this won't work as it is a core field and not a custom field - hence, why I'm asking what code should look like when referencing a core field.  Any help would be much appreciated, thank you.

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2018

FixVersions act and stored differently than drop down field, it's a collection.

You have a code solution here:

https://community.atlassian.com/t5/Marketplace-Apps-questions/JIRA-Script-Runner-Append-version-to-Fix-Version-s/qaq-p/593416

Like Dave Liao likes this
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2018

Let me know if you managed to make it work for you

Melinda Atkinson
Contributor
December 11, 2018

Thanks Nir - not had a chance to try yet, but will keep you posted.  Thanks for your assistance so far.

Suggest an answer

Log in or Sign up to answer