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.
×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.
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.