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

Scriptrunner: Version Picker Question

I haven't worked much with scripted fields and the documentation here doesn't seem to talk about returning a Version Picker.  Is that a custom field?

Here's what I'm trying to do.  I created a custom field called "Planned Fix Version", which I want to script with the following logic: 

For this issue, look through the versions for the project it is a part of, and if at the start date of that version, that issue has the FixVersion field set to that version, set Planned Fix Version to that FixVersion.  Make sense? 

The documentation says that you can "You can either point to a script accessible to jira using an absolute path", so does that mean if I have a JQL query saved I can reference that?  I think I know how to do this with JQL, but not groovy.

1 answer

Worked on this today (goal is to snapshot the planned version at the start of a release), it's a start, but definitely not right yet.

import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.getProjectManager()
def versionManager = ComponentAccessor.getVersionManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

// get the history of the fixVersion field for the issue
def changeHistoryForIssueFixVersion = changeHistoryManager.getChangeItemsForField(issue, "FixVersion") //returns List<ChangeItemBean>

// get the project associated with the issue
def issueProject = issue.getProjectObject() //returns type Project

// get the list of versions associated with the project
def projectVersions = versionManager.getVersions(issueProject) //returns List<Version>

// loop through the list of versions
for (version in projectVersions) {
   // get the start date for the version
   def versionStartDate = version.getStartDate() //returns Date
   
   // look up what the fixVersion was on the start date
   for (item in changeHistoryForIssueFixVersion) {
   
      def timeStamp = item.getCreated() // returns TimeStamp
      
      if (timeStamp < versionStartDate ) {
        
         if (item == version){
            // if it's the same as the version we are looking at
            // return the version we are looking at
            return item // TBD, figure out how to have this return a Version
         }
      }
   }
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Localize Smarter with the Transifex Integration for Bitbucket

Over 52% of internet users say obtaining information in their own language is more important than price and 75% of the world’s population doesn’t speak English. It’s no wonder then that successful gl...

253 views 0 3
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