Hi, one of my script listeners is not working as expected after upgrading jira fom 7.5 to 7.12.1. What the script listener is supposed to do (and it was working just fine for over a year on jira 7.5) is that when a custom field is updated, the previous value in that custom field should be removed from the Fix Versions field and the new value in that custom field should be added to the Fix Versions field. So, for instance, if the custom field had value Version1 and Fix Versions field had values VersionX, VersionY, Version1, VersionZ, and the custom field is set to value Version2, then Fix Versions should be then VersionX, VersionY, VersionZ, Version2. What it stopped working is the line when I removed the previous value in the custom field from the Fixed Versions field (using the above example, Version1 is not removed from the list of values in Fix Versions field). Complete script below
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.index.IssueIndexingService
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Target Release"}
if (change) {
log.warn("content of change " + change)
def previous = change.oldstring
log.warn("previous " + previous)
IssueManager issueManager = ComponentAccessor.getIssueManager()
def versionManager = ComponentAccessor.getVersionManager()
def key=issue.getKey()
Object plugin = ComponentAccessor.getPluginAccessor().getPlugin("com.valiantys.jira.plugins.SQLFeed");
Class serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldDisplayService");
//ComponentManager componentManager = ComponentManager.getInstance();
def componentManager = ComponentAccessor.projectComponentManager
//Object fieldDisplayService = componentManager.getOSGiComponentInstanceOfType(serviceClass);
Object fieldDisplayService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass);
Object displayResult = fieldDisplayService.getDisplayResult(key, "customfield_12100");
String display = ""
display = displayResult.getDisplay();
log.warn("display: " + display)
def CurrentVersions = issue.getFixVersions()
log.warn("current versions: " + CurrentVersions)
Project project = issue.getProjectObject()
Version versionFX = versionManager.getVersion(project.getId(), display as String)
Version previousversion = versionManager.getVersion(project.getId(), previous as String)
log.warn("versionFX: " + versionFX)
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
MutableIssue issue = (MutableIssue) issueManager.getIssueObject(key)
if (display != null && versionFX == null) {
versionManager.createVersion(display as String, null , null , project.id, null)
}
versionFX = versionManager.getVersion(project.getId(), display as String)
log.warn("versionFX: " + versionFX)
if (versionFX == null){
CurrentVersions.remove(previousversion)
issue.setFixVersions(CurrentVersions)
}else{
CurrentVersions.remove(previousversion)
log.warn("after remove: " + CurrentVersions)
CurrentVersions.add(versionFX)
log.warn("after add: " + CurrentVersions)
issue.setFixVersions(CurrentVersions)
log.warn("appended versions: " + CurrentVersions)
//issue.setFixVersions([versionFX])
}
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id))
}else
log.warn("no change of Target Release")
return