Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19: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.
×I have a date and time field that is blank by default but I would like the field to be mandatory at ticket creation if a certain option is selected in a different custom field.
Scenario:
Option 1
If Option A of Field A (dropdown list single choice) is selected, Field B (date & time field) is not mandatory and the ticket can be created.
Option 2
If Option B or C of Field A (dropdown list single choice) is selected, Field B (date & time field) is mandatory and the ticket cannot be created.
I have tried to use a "Simple Scripted Validator" from Scriptrunner without success.
My last code attempt were:
(cfValues['Field A'] == 'Option B' && cfValues['Field B'] != null)
(cfValues['Field A'] == 'Option B' && cfValues['Field B'] == null)
(cfValues['Field A'] == 'Option B' || cfValues['Field B'] != null)
(cfValues['Field A'] == 'Option B' || cfValues['Field B'] == null)
All of them failed either by allowing the creation when it should be blocked or by blocking the creation when it should be allowed.
Can anyone help with this code?
Thank you
Hi, @Eduardo Marques
You have to use Behaviour (it works with issue creation screens), not Validator, that works on transition.
Just yesterday I answered on similar question. Take a look please:
Thank you Evgeniy.
I removed the parts I did not need and I was able to make it work with the following code:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
FormField affectedField = getFieldById(getFieldChanged())
def affectedVal = affectedField.value
FormField gvField = getFieldByName("Report Date & Time")
if (affectedVal == "E-mail") {
gvField.setRequired(true)
} else {
gvField.setRequired(false)
}
Perfect
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For your requirement, you will need to use a Server-Side Behaviour for Field A.
Below is a sample code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def fieldA = getFieldById(fieldChanged)
def fieldAValue = fieldA.value.toString()
def fieldB = getFieldByName('Field B') // rename the field accordingly
if (fieldAValue == 'Option A') {
fieldB.required = false
} else if (fieldValue in ['Option B', 'Option C']) {
fieldB.required = true
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
The code above should meet your requirement. If Field B is required and the value for it is not set, a validation error will be displayed.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram,
Thank you for your reply. I tested it also and it works. There was a typo in the else if and I correct so it works perfectly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.