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

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
Accepted answer

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())

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
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,148 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you