My requirement is to update an issue on transition (post function) to append the next unreleased version to Fix Version/s. I have managed to do the first part, i.e. find the next unreleased fix version.
import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Logger import org.apache.log4j.Level import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.project.Project import com.atlassian.jira.project.version.Version import com.atlassian.jira.project.version.VersionManager import com.atlassian.jira.event.type.EventDispatchOption 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) newversions = newversions.sort({version1, version2 -> version1.releaseDate<=>version2.releaseDate}).findAll{version -> ! version.released } def versionToUse = newversions.first(); log.debug("First element: " + versionToUse) issue.setFixVersions([versionToUse])
And I can also update the Fix Version/s field.
The problem is that this code will overwrite the Fix Version/s, I want to append. And I guess that when I append I want to check that the version I am appending doesn't already exist.
Thoughts
Hello Roy:
You can use something like this:
/*You fetch the fixVersions from the object,
the function returns Collection<Version>*/
def versions = issue.getFixVersions()
/*Then you check that the version that you found is not contained
in that collection*/
if(!versions.contains(versionToUse)){
/*Append your version to the collection in whichever way
you find appropiate*/. versions.add(versionToUse)
/*And then set the new array that containes the old value
and your*/ issue.setFixVersions(versions)
}
/*If it is contained, then you don't have to do anything
Because it is already there*/
This should work correctly.
The function I use is documented here
If I misunderstood anything that you wanted to do, or if it doesn't work correcly, let me know and I'll be glad to have another look at this.
Good luck!
DYelamos
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.