Automatically set next unreleased fixVersion for new issues or during a transition?

Hi,

I would like to automatically set next unreleased fixVersion for new issues or during a transition.

I belive "script runner" is my only option?

If so, does anyone have written somthing like that?

How can I get the "next unreleased fixVersion" using jira API?

Any help would be appriciated

2 answers

1 accepted

0 vote

Something like this, not tested:

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey("JRA")

def versions = versionManager.getVersions(project)

versions.sort {it.releaseDate}.reverse().find{! it.released}

works like a charm

As I'm sharing the WL, Can I use somthing like that ?:

import com.atlassian.jira.component.ComponentAccessor;

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)
 
def versions = versionManager.getVersions(project)
 
versions.sort {it.releaseDate}.reverse().find{! it.released}

The above code didn't work (version 7 maybe?) as it reported UnmodifiableListIterator, so I have managed to find another way.

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)

def versions = versionManager.getVersions(project)

def newversions = versions.collect()
  
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
  
//log.debug newversions
//newversions.eachWithIndex { version, i ->
    //log.debug "${version.description} - ${version.name} - ${version.released}"
//}

//versions.sort {it.releaseDate}
newversions = newversions.sort({version1, version2 -> version1.releaseDate<=>version2.releaseDate}).findAll{version -> ! version.released }

log.debug("First element: " + newversions.first())
//newversions.eachWithIndex { version, i ->
    //log.debug "${version.description} - ${version.name} - ${version.released}"
//}

def versionToUse = newversions.first();

You can use earliestUnreleasedVersion(projectKey) (see Substitution variables) as a substitution variable on a workflow transition to set the fix version. This is available for Create Issue, Create Subtask, and Update issues post functions.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 6 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

27 views 0 2
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