Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script runner - version selection

Ellie M_ I'm New Here Jul 15, 2021

A beginner - question regarding the script runner.
The code below correctly returns the version with the highest ID (the last created version). 

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.*

if (getActionName() != "Create Issue") {

def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersions(issueContext.projectObject)
if (versions)

How to properly enhance this script to show the last created version, but only taking versions that start with / that have, e.g. "RC_*" in their name? 

I'm hoping for your help after many hours invested in learning and testing methods proposed for slightly different cases - which unfortunately returned () for me.

Thanks a lot!

1 answer

1 accepted

Hi @Ellie M_

For your requirement, you could add a basic if/else filter to your code as shown below:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours behaviours

def versionManager = ComponentAccessor.versionManager
def affectedVersions = getFieldById(AFFECTED_VERSIONS)

def versions = versionManager.getVersions(issueContext.projectObject)

def filteredVersions = [] as List<Long>

versions.each {
if("RC_")) {


Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the versions available for testing:-


Below is a print screen of the sample test. As expected, the latest RC version is selected.


I hope this helps to solve your question. :)

Thank you and Kind Regards,


Ellie M_ I'm New Here Jul 16, 2021

It absolutely helped, Ram!
With some fine-tuning after testing, it now perfectly serves the need. 

Thank you so much for the prompt help. Much appreciated!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

👁‍🗨 Confluence Team planning dashboard_Atlympics 🌈

Hi Atlassian's, How is your journey with #Atlympics 2021 so far....excited! Me too, same excitement. Here's my typical team planning and vision dashboard which I used to share to my management and ...

93 views 1 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you