how to get released versions using "getVersionsReleased" method in groovy in Behaviours Plugin?

fabby May 30, 2012

my jira version is 4.4.1.

i put a validator on "description".and add the validation script below,but the field "description" gets no result.

import com.atlassian.jira.project.version.VersionManager
FormField formDescField=getFieldById("description")

List<VersionManager> versions=getVersionsReleased(10101,true) as List
formDescField.setFormValue(versions.first().getName())

anyone knows how to use the method "getVersionsReleased"

1 answer

1 accepted

1 vote
Answer accepted
CEDRIC ZABEL
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.
May 30, 2012

While you’re developing this, you should turn on logging for the Behaviours plugin and check the logs when something goes wrong. In this case, you’d see that your code is throwing exceptions and never even gets to the part where setFormValue is executed.

The problem here is that you can’t just call getVersionsReleased as a bare function. It’s a method of a VersionManager object, but you never got a VersionManager object. You only imported the class, which isn’t enough.

To get the VersionManager object, you can first get the ComponentManager object and call getVersionManager() on it, and to get the ComponentManager object you can import com.atlassian.jira.ComponentManager and call getInstance() on the class. getInstance() is a static function.

(I wish I could point you to some docs on this, but there don’t seem to be any good ones. I had to learn it by puzzling over example code.)

Try this:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.version.VersionManager

ComponentManager componentManager = ComponentManager.getInstance()
VersionManager versionManager =  componentManager.getVersionManager()

FormField formDescField=getFieldById("description")
 
List<VersionManager> versions=versionManager.getVersionsReleased(10101,true) as List
formDescField.setFormValue(versions.first().getName())

fabby May 31, 2012

thanks,Cedric

it works using your code.

another question:

you say Behaviours Plugin can logging.so i turn on logging for the plugin.

i searched out the JIRA installation location,can only find log files in JIRA\Atlassian\Application Data\JIRA\log.and found three log files:atlassian-jira.log,atlassian-jira-security.log,atlassian-jira-slow-queries.log.

open atlassian-jira.log,i didn't see any error messages about this plugin if i put wrong script into the plugin on purpose.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events