Forums

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

VersionManager.getVersion returns error in Behaviours

Joe Mallon
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.
August 30, 2021

Jira 8.5.1, ScriptRunner 6.33

I have the ID of a version and am trying to get its name, but Behaviours doesn't respect the getVersion() method.

Script:

import com.atlassian.jira.component.ComponentAccessor

def fixV = getFieldById(getFieldChanged())
def fixVValue = fixV.getFormValue()

def VersionManager = ComponentAccessor.getVersionManager()
def newFixVersion = VersionManager.getVersion(fixVValue)

Error on last line:

Cannot find matching method com.atlassian.jira.project.version.VersionManager#getVersion()

 getVersion is a method of VersionManager:

https://docs.atlassian.com/software/jira/docs/api/8.5.1/com/atlassian/jira/project/version/VersionManager.html#getVersion-java.lang.Long-

Why does Behaviours not respect that method?

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
September 1, 2021

If you actually tried to execute the behavior and looked in the log file, you would see something like this:

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.project.version.DefaultVersionManager.getVersion() is applicable for argument types: (String) values: [35720]

This gives more details... such that it tried to call the getVersion() method with a string (default data type returned by behaviors but the method expects a Long.

You can also easily examine the value during debugging to find what data type to expect and what conversion might be needed by putting this in your behavior:

def fixV = getFieldById(getFieldChanged())
fixV.clearHelpText()
def fixVValue = fixV.getFormValue()
fixV.setHelpText("$fixVValue ${fixVValue.getClass()}")

Then try it in an issue and you will see this below your field:

37325 class java.lang.String

Or the following if you select more than 1:

[37325, 37532] class java.util.Arrays$ArrayList

If you are confident that you will only allow one value, the fix is as simple as

def newFixVersion = versionManager.getVersion(fixVValue as Long)
 
Joe Mallon
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.
September 10, 2021

The Help Text helped me figure out the rest - thanks!

0 votes
Leo
Community Champion
September 1, 2021

Hi @Joe Mallon,

"VersionManager" is a pre-defined class. you may need to define custom variables in your script

also "getVersion()" method takes Long value as parameter. is your field returns Long value

you can try below code to see if that gives you luck

import com.atlassian.jira.component.ComponentAccessor

def fixV = getFieldById(getFieldChanged())
def fixValue = fixV.getFormValue() as Long

def vm = ComponentAccessor.getVersionManager()
def newFixVersion = vm.getVersion(fixValue)

 

BR,

Leo

Suggest an answer

Log in or Sign up to answer