Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Select list field allowed to set to None on View screen inspite of being required on edit screen

Vineela Durbha
Contributor
October 19, 2022

Hi Team,

I have a select list field (field B)and it becomes required on the selection of value of another select list field(Field A). This is implemented through behaviours.

But the problem is that the field b is allowing users to set to "None" which should not be the case as it is required on edit screen.

  • How to make field not to get updated to None on view screen as it is required on both create, edit and transition screens?

1 answer

0 votes
Olly von Fay-Siebenburgen _ScriptRunner_
Contributor
October 24, 2022

Hi Vineela!

Olly here from Adaptavist Support!

Background Information:


This is due to Jira's "Required" and ScriptRunner Behaviour's "Required" are slightly different.

When a Select List field is made "Required" in Jira's settings, it removes the "None", but when you make it Required through ScriptRunner, it does not remove "None".

However, setting a field to required through Jira's settings, we can not change its requirement through a Script as you are trying to do!


Solution:

What we can do to achieve your requirement however, is to add some validation to the (Field B's) Select List, to check the value, and if it is "None", we display an error message for the user.

I have two fields called 'Select List A B' and 'Select List C D'.

If 'Select List A B' is set to A, then 'Select List C D' should be set to required.

Within my Behaviour, I've added both 'Select List A B' and 'Select List C D'.
They both have Server-Sided Scripts:

'Select List A B''s Script would look like this:

//Get Select List A B's Custom Field and value
def
selectListAB = getFieldByName("Select List A B")
def selectListABValue = selectListAB.value

//define Select List C D's Field
def selectListCD = getFieldByName("Select List C D")

//If Select List A B's value is 'A'
if(selectListABValue == "A"){
//set Select List C D as required
selectListCD.setRequired(true)

} else {
//otherwise, set Required false
selectListCD.setRequired(false)
//and clear any lingering errors
selectListCD.clearError()
}

'Select List C D''s Script would look like:

//Get Select List C D's Custom field and value
def
selectListCD = getFieldByName("Select List C D")
def selectListCDValue = selectListCD.value

//if Select List CD's value is null, and the field is required
if (selectListCDValue == null && selectListCD.isRequired()){
//Set the error
selectListCD.setError("This field can not be None!")

} else {
//otherwise, clear the error
selectListCD.clearError()
}

If it's still unclear where these Scripts go, here's the actual location within the Behaviour:

Screenshot 2022-10-24 at 15.12.46.png

I hope this answers your query! Let me know if you have any other questions, I'd be more than happy to help :) 

Kind Regards,

Olly

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events