problem with a script listener after upgrading jira from 7.5 to 7.12.1

Tomas Arguinzones Yahoo October 1, 2018

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

1 answer

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2018

Hello @Tomas Arguinzones Yahoo

What is scriptrunner version?

And can you inspect atlassian-jira.log

There you can find some useful info about cause of problem.

Tomas Arguinzones Yahoo October 2, 2018

Hi Mark...scriptrunner version is 5.4.28.

 

I will re-check the log but first look I did not notice any error related to this. This line: CurrentVersions.remove(previousversion)  just stopped doing what is supposed to do (remove the value pass from the array list of versions in variable CurrentVersions). Interesting enough, the next line: CurrentVersions.add(versionFX), which add new version to the variable CurrentVersions still works fine.

 

Thanks

Tomas Arguinzones Yahoo October 2, 2018

Hi Mark,

I know what is happening but I am not sure how to fix it and it is not related to the remove method but to nFeed field. The script listener experiencing the problem triggers on Issue Update event when the value of the nFeed field is changed by the user, so I have these lines in my listener:

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)

Before the upgrade, the variable change was showing the string values (old and new) of the nFeed field, but now, it shows the values IDs, like this:

change = [newvalue:1339, field:Target Release, oldstring:1338, newstring:1339, id:5057927, fieldtype:custom, oldvalue:1338, group:3761304]

so change.oldstring is returning 1338 and of course that means nothing to the user (I need the string value as it was happening before the JIRA/nFeed/scriptrunner upgrade).

May you let me know how to get the string value of the previous value the nFeed field had? I know how to get the new value as per the documentation but I dont know how to get the previous value.

Thank you in advance for your help

 nFeed version 5.13.11

JP _AC Bielefeld Leader_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2018

Hi Tomas,

IMHO I would ask the Valiantys team on the nFeed issue. They changed quite a lot when upgrading from 5.12 to 5.13

You can try to install the latest 5.12.x version of the nFeed addon & repeat the tests. We also learnt it the (rather) hard way having similar issues that you have.

Best

JP

Suggest an answer

Log in or Sign up to answer