Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to make a text field required based on the selection of another field

Todd Winton
Contributor
November 10, 2023

I have a script in a scriptrunner validator to validate a value is populated when another value is selected.  Here is the script:

issue.customfield_10177?.value == "Remote Location" ? issue.customfield_10178 != null : true

10177 is a check box

10178 is a text field

When I select that value and leave the text field blank, it is not giving a validation error.  Is this because of the field type?

1 answer

0 votes
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.
November 10, 2023

Hi Todd,

I can confirm we have an example validator located here on line 59, which shows how you can validate that a checkbox field has one specific value selected and that a single line text field is not null.

You can take this validator and use it to help create the validator you need to solve your requirement.

I hope this answer helps.

Regards,

Kristian

Todd Winton
Contributor
November 14, 2023

@Kristian Walker _Adaptavist_ 

Is the length of the checkbox field important?

I updated the script to

issue.customfield_10177[0].value == "Remote Location" && issue.customfield_10178 != null : true

and am now getting an error on all attempts to use this validator:

The following validator rejected the transition: ScriptRunner Script. The configuration is invalid. Contact the app vendor that provided this workflow element.
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.
November 15, 2023

Hi Todd,

This error means the Expression failed, as your syntax for the Jira Expression Framework provided by Atlassian which we use is invalid.

Specifying the length of the checkbox makes the syntax correct and means that this is the only value selected. 

If you want any of the values in the field to match then I have added a new example here on line 64 that you can use to achieve this.

I hope this helps.

Regards,

Kristian

Suggest an answer

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

Atlassian Community Events