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

setRequired feature is not auto refreshing

Sravya Vuggina August 30, 2018

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 -

1st time.pngExpected.png2nd time.png

 

 

 

 

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2018

Hello,

How did you make it required? Did you write code?

Sravya Vuggina August 30, 2018

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)

    }

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2018

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?

Sravya Vuggina August 30, 2018

Yes I did. Mapped to the Feature Request Category field and the project / Issue Type. 

Sravya Vuggina August 30, 2018

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. :) 

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2018

Good to hear! :)

Suggest an answer

Log in or Sign up to answer