Restrict fix version field to accept a single value

Likhita April 30, 2024

Hi ,

I am trying to restrict fix versions field to accept a single value , can anyone provide suggestion on how can we achieve that from behaviours.

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2024

You must create your behaviour against the Fix Versions field so that the script is evaluated each time the field is modified.

And the script can be greatly simplified compared to the other post.

If you are just putting the script directly in the behaviour screen, you only need these 4 lines:

def fixVersionField = getFieldById('fixVersions')
fixVersionField.clearError()
if((fixVersionField.value as List).size() >1){
fixVersionField.setError('Please select a single value')
}

If you use an IDE to write your scripts and want the autocompletion to work, you can add these 3 lines at the top:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 30, 2024

Hi @Likhita ,

this is an old suggestion https://jira.atlassian.com/browse/JRASERVER-15496 that has never been implemented.

My suggestion is to create a your own validator at workflow level or to put in place a behaviour provided by scriprunner plugin (https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Restrict-Fixversion-to-one-value/qaq-p/214696)

Hope this helps,

Fabio

Likhita April 30, 2024

Hi @Fabio Racobaldo _Herzum_ 

Thank your for your reply.

I tried with the code provided there its working expected when selecting with the existing versions when if incase two new versions its not throwing an error.

Could you please sugguest how can we manage with the newly created ones please.

This is the code which I Have modified and used 

________________________________________________________________

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def fixVersionsField = getFieldById("fixVersions")
def selectedVersions = fixVersionsField.getValue() as List

// Ensure only one version is selected
if (selectedVersions.size() > 1) {
fixVersionsField.setError("Please select a single value")
}
else if (selectedVersions.size() == 0 || selectedVersions.size() == 1)
{
fixVersionsField.clearError()
}

_________________________________________________________________________________

Suggest an answer

Log in or Sign up to answer