Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

set a custom field mandatory based on field's selection

QK November 30, 2018

Hi! 

I have one question.  For example I have a fieldA that has values (Val1 , Val2,Val3) 

If I  select val1 and val2 I want to change another fieldB and make it mandatory, if Val3 is chosen , nothing should happen. How can I do that? 

 

1 answer

1 accepted

1 vote
Answer accepted
Tansu Akdeniz
Community Champion
November 30, 2018

Hi @QK,

Do you have Script Runner plugin? If yes,

  • Go to Behaviours
  • Add new mapping to your project and issutype
  • Add new field (choose fieldA)
  • Add server-side script and paste the code
def fieldA = getFieldById(getFieldChanged())
def fieldB = getFieldById("customfield_xxxxx")

String selectedOption = fieldA.getValue();

if(selectedOption.equals("Val1") || selectedOption.equals("Val2")){
fieldB.setRequired(true)
} else {
fieldB.setRequired(false)
}

Btw, there are different plugins on marketplace that provides this feature.

Tansu

QK November 30, 2018

Thank you,

I tried it but it doesn't work. Maybe I am writing something incorrectly. Can you tell me what field should I write in 

getFieldById("customfield_xxxxx")

 ?

Tansu Akdeniz
Community Champion
November 30, 2018

Please write your customfield id of fieldB. Ex: customfield_12345.

In order to find it;

  • Go to "Issues -> Custom Fields -> %Your customfield%"
  • Than click the Edit button.
  • You should see the cf id in URL.
Like QK likes this
Tarun Sapra
Community Champion
November 30, 2018

Hello @QK

You can also use

getFieldByName(<name of your custom field>)

Please see the APIs here

https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html

Like QK likes this
QK November 30, 2018

Thank you!!!! 

Suggest an answer

Log in or Sign up to answer