Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,079
Community Members
 
Community Events
165
Community Groups

Hide certain version options for custom field Version Picker (multiple) using Behaviours

I'm looking for a certain groovy script I could use in ScriptRunner's Behaviours for my custom field that uses the Version Picker (multiple) type.

For our project, we have multiple Releases (e.g. 101, 102, 103, 201, 202, 203 etc) and we always add more release numbers throughout the year.

We use a custom fields to help filter, but we want to show only the 200s options. We use Version Picker custom field because on JQL query, it's easier to search: customfield >= 200, and we'd never have to change that query. 

My question, is there a script I could use in Behaviours set to the custom field so that it searches using a wildcard for the different versions available in our project, and then hides the other options (the 100s) from being selected?

Right now I have this that works for now, but I'd rather not have to update this script every time we create a new version number:

def field = getFieldByName ("Version Picker Option")
def version = field.getValue() as Collection
def options = field.setFieldOptions (["200","201","202"]) //must update every quarter, but would rather there be a wildcard option

if (options == true){

   field.setValid(false)
   field.setError("Version/s can not be a 100s")

}else {

   field.setValid(true)
   field.clearError()

}

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry Community Leader May 18, 2022

Hello @Diana Gorv ,

I tried finding the valid versions for the issue, but did not succeed, so I retrieved the project versions instead. Please try this snippet : 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def threshold = 200
def versionPicker = getFieldByName ("Version Picker Option")
def validVersions = issueContext.getProjectObject().getVersions().findAll{ it.name.toDouble() >= threshold}
versionPicker.setFieldOptions(validVersions)

Hi @Antoine Berry 

I can't screenshot and share, but I copied your script and unfortunately I can still see the other versions as selectable.

Antoine Berry Community Leader May 20, 2022

Hi @Diana Gorv ,

Could you check the logs for any error ?

Hi @Antoine Berry 

I checked in Built-In Scripts > View Server Logs and couldn't find anything. I even checked in Systems > Logging and Profiling and tried different logging levels to view the server logs. Unfortunately, I'm not to familiar with looking into database logs either. 

The script doesn't come up with any red errors in behaviors though. I tried changing threshold to the project's release ID number to see if it changed anything, but I don't think I did the correct method.

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def threshold = 12345 // found this in Project > Releases > clicked the version name and saw last 5 digits on url
def versionPicker = getFieldByName ("Version Picker Option")
def validVersions = issueContext.getProjectObject().getVersions().findAll{ it.name.toDouble() >= threshold}
versionPicker.setFieldOptions(validVersions)

If a wildcard search is not possible for Jira's version picker in groovy, then I can make do with my original script.

Antoine Berry Community Leader May 23, 2022

Hello @Diana Gorv ,

Since you have scriptRunner, if you do not have access to the server you can check the logs by using the "View server log files" feature. There you should select the "atlassian-jira.log" file. You can add logs in the script if you want.

Also the threshold variable should be 200 in your example, so please use something like this : 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def threshold = 200// minimum version number
def versionPicker = getFieldByName ("Version Picker Option")
def validVersions = issueContext.getProjectObject().getVersions().findAll{ it.name.toDouble() >= threshold}
log.error("valid version are : " + validVersions)
versionPicker.setFieldOptions(validVersions)

Hi @Antoine Berry 

I was able to view the server log files, and I found this error "Script function failed on issue: issue: ABC-98765, user: dgorv, :fieldID: customfield_01234, file: <inline script>" java.lang.NumberFormatException: multiple points

I guess I should mention we have  some of our version naming convention with multiple decimals (i.e 200.1.1, 200.1.2 etc) I don't know if that plays a factor. I can't exactly copy and paste my logs over since it's on a airtight server.

Like Antoine Berry likes this
Antoine Berry Community Leader Jun 21, 2022

Hi @Diana Gorv ,

Really sorry for the super late answer. The multiple dots indeed are the problem.

Could you please try this script : 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def threshold = 200 // minimum version number
def versionPicker = getFieldByName ("Version Picker Option")
def validVersions = issueContext.getProjectObject().getVersions().findAll{
def version = it.name
if (version.contains(".")) { version = version.substring(0,version.indexOf(".")) }

version.toDouble() >= threshold

}
log.error("valid version are : " + validVersions)
versionPicker.setFieldOptions(validVersions)

this works! Thank you so much!

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,377 views 36 44
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