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:
Why does Behaviours not respect that method?
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)
The Help Text helped me figure out the rest - thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.