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.
×I am fairly new to Script Runner Behavior and trying to write scripts with the help on examples available online – I must be missing something very obvious. :)
Based on the value Feature Request Category(FRC), mandatory/ optional settings of Model field must vary.
I have used script runner to dynamically mandate Model when FRC value is “Missing Special Test” and optional when FRC value is “Missing Vehicle Model”.
Model field is getting displayed as optional when Missing Vehicle Model is selected for the first time, but when the value of FRC is switched to Missing Special Test (where Model field is mandatory) and back to Missing Vehicle Model – Model field is not automatically switching to optional.
How to make it optional every time Missing Vehicle Model is selected?
Here are some screenshots -
Hello,
How did you make it required? Did you write code?
Yes - please find my code below.
Should I be exclusively mentioning model.setRequired(false) in the if condition for Missing Vehicle Model?
def category = getFieldByName("Feature Request Category")
def year= getFieldByName("Year")
def make= getFieldByName("Make")
def model = getFieldByName("Model")
def crField = getFieldById(getFieldChanged())
def selectedOption = crField.getValue() as String
if ((selectedOption.contains("Missing Vehicle Model")))
{
year.setRequired(true)
make.setRequired(true)
}
else
{
year.setRequired(true)
make.setRequired(true)
model.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you attach this code to the Feature Request Category? I mean, you added the Feature Request Category to your behaviour and added this code in this field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I did. Mapped to the Feature Request Category field and the project / Issue Type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Added a line of code model.setRequired(false) to the if condition -first case and it seems to be working fine now. No matter in what order Feature Request Category values are selected the behavior of Model field seems to be working as expected. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good to hear! :)
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.