How to make field required on issue creation based on the multiple choice of another field by Script

Julia Petrova February 12, 2025

I'm trying to add a Behaviour by ScriptRunner to make a field required if in another field multiple values are selected. But it seems the code I created is not working for checkbox field.

For example, I have follwoing fields:

"Field1" - text field type

"Field2" - checkbox field type with a following values: 1, 2, 3, 4

And on issue creation I need "Field1" be required only if 1 and/or 2 values are selected in the "Field2".

 

Code example I used:

const field1 = getFieldById("field1id");

 

const changedField = getChangeField();

 

if(changedField.getName() == "field2" && changedField.getValue().value.contains("1", "2")) {
        field1.setRequired(true);
}
In Behaviour: Event is "On change" and View is "Create View".

 

But it doesn't work at all. I've tried different options for getting values from the "field2" change, but failed in this. What am I doing wrong?

I found a few solutions for the same requests in community but they were for Jira Server, while I'm using Jira Cloud and those solutions didn't help.

Thanks in advance!

1 answer

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2025

Hi Julia,

Thank you for your question.

I can confirm that you can use the approach in the example script here to make a text field required when a value is selected in a checkbox field.

This script makes a select list when an option is selected in a multi-select list field. You can update this part to make the text field required.

Also, in your case, you will need to duplicate the changeField condition to check if it is either option by making it like changedField.getValue().some(item => item.value === "1") || changedField.getValue().some(item => item.value === "2")

I hope this helps.

Regards,

Kristian

Julia Petrova February 13, 2025

It works! Thank you so much for your help!

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2025

You are welcome

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events