Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

After scriptrunner update VersionManager.getVersionsByName returns error in Listener

Deleted user April 5, 2022

JIRA 8.20.3

ScriptRunner for JIRA 6.47.0

Listener starts throwing error after scriptrunner update
for every method in com.atlassian.jira.project.version.VersionManager
///Error for strings:


def oldValue = versionManager.getVersionsByName(change["oldstring"]).first()
def newValue = versionManager.getVersionsByName(change["newstring"]).first()

[Static type checking] - Cannot find matching method
com.atlassian.jira.project.version.VersionManager#getVersionsByName(java.lang.Object). Please check if the declared type is correct and if the method exists.

Script


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

if (event.issue.issueType.name == "Bug" || event.issue.issueType.name == "Field Issue")
{
def loggedInUser = ComponentAccessor.userManager.getUser("automation_user")
def issueManager = ComponentAccessor.getIssueManager()
def versionManager = ComponentAccessor.versionManager
def changeItems = event?.getChangeLog()?.getRelated("ChildChangeItem")
def change = changeItems.find

{ it['field']=='Origin Affects Version' }

if (change)
{
log.warn("Issue is Bug/FI and Origin Affects Version was changed. Actions applied")
def issue = issueManager.getIssueByCurrentKey(event.issue.key)
def oldValue = versionManager.getVersionsByName(change["oldstring"]).first()
def newValue = versionManager.getVersionsByName(change["newstring"]).first()
Collection affectedVersions = issue.affectedVersions as Collection

if (!affectedVersions.contains(newValue))

{affectedVersions.remove(oldValue)
issue.setAffectedVersions(affectedVersions) issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false) }


}
}

 

1 answer

0 votes
Sam Bartolome
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.
April 8, 2022

Not much into scripting, but I think the line below misses the () after versionManager

def versionManager = ComponentAccessor.versionManager

It should be as 

def versionManager = ComponentAccessor.versionManager()

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events