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

Populate custom date field with release date of the version selected in custom version type field

Custom Fields:
Iteration: Version type Single select field - displays list of all versions for the selected project.
Production Date: Date type

Requirement: Need to populate 'Production Date' with the release date of the version selected in the 'Iteration' field.

Note:
-> We are using a custom field for selecting the version as we want to restrict single version selection on the issue.
-> We cannot take 'Production Date' as a scripted field as we want the date to be input by user in case of a particular version of 'Off Cycle'
      
We are trying out the Behaviours functionality to achieve the same and are stuck at a point where jira crashes when the behaviour executes.

The below code executes without error and we are getting the selected version from 'Iteration' field in temp.

import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersions(issueContext.projectObject)

def itr = getFieldByName("Iteration")
def prod = getFieldByName("Production Date")

def abc = itr.getValue() as String
def temp = abc.substring(abc.lastIndexOf("[")+1,abc.lastIndexOf("]"))

We now want to read the entire version list (versions) and compare each version name with 'temp' to find the version whose Release date needs to be fetched and put in Production Date.

We appended the below code to see how versions can be read and JIRA crashed.
def xyz = getFieldByName("Test Field")  //'Test Field' is a text type field
xyz.setFormValue(versions[0])

Please guide us how this can be achieved. We are thinking of somewhat like below but unable to try out as cannot risk JIRA to be down again.

for(i in versions)
    {
    def name = i.getName()
    if(temp == name && temp !="Off Cycle")
      {
      def release = i.getReleaseDate()
      prod.setFormValue(release)
      }
    }

We are in the process of JIRA license purchase and the  above requirement is critical.

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov Community Leader Aug 21, 2018

Hello @Neetika Kumar

Yes, the problem happens because you ve tried to set Version object in text field.

Your suggestions are correct. Another variation of script

import com.atlassian.jira.component.ComponentAccessor


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

def itr = getFieldByName("Iteration")
def prod = getFieldByName("Production Date")

def abc = itr.getValue() as String
log.error("Iteration value: ${abc}")
def temp = abc.substring(abc.lastIndexOf("[")+1,abc.lastIndexOf("]"))
log.error("Iteration value cleaned: ${temp}")

def version = versions.find {it.name == temp && temp != "Off cycle"}
if (version){
def releaseDate = version.getReleaseDate()
prod.setFormValue(releaseDate)
}

 And it is good practice to log variables. That allows you see what values variables contains in atlassian-jira.log while your script executes.

Thanks Mark. The script worked great.

Just one addition I did to the script to populate date instead of date time in Production Date.

def version = versions.find {it.name == temp && temp != "Off cycle"}
if (version){
    def releaseDate = version.getReleaseDate()
    String newDate = releaseDate.format("dd/MMM/yy")
    prod.setFormValue(newDate)
}

 

Thanks!

We are trying to auto populate a custom field. e.g. product version, based on the customer's organization and value selected in another custom field e.g. product.

We want the product version field to be auto-populated with the appropriate value before the service desk agent views the ticket in JSD.

Will the above proposed solution work and does this require a plugin?  

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

275 views 1 2
Join discussion

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