How to get the 'Free Text Field' type custom field value and set it as required field?

Dear all,

During I using the JIRA Behaviours Plugin to add some validations for some custom fields, I found that for 'Select List' type or 'Text Field' type, use following script code can work:

==================================================================================

FormField AField = getFieldByName("External Party") // this is a select list type field

FormField BField = getFieldByName("DEV Remark") // this is a text field type field

BField.setRequired(false)

if ((AField.getValue() != null) && (BField.getValue() == "")){

BField.setRequired(true)

}

===================================================================================

but, for 'Free Text Field' type field, use upper code to check, it seems can't work:

e.g. CField is a 'Free Text Field' type field, uses 'CField.getValue()' to get the input value in it, even the field contains the input value, 'CField.getValue()' still return null, and use following method to this field, it also has not any show or prompt:

CField.setRequired(true)

CField.setError("test error")

For this case, may I ask that about 'Free Text Field' type custom field, how to get its input value and how to set it as require / set error to it? thanks.

1 answer

This widget could not be displayed.

Instead of checking for empty strings and nulls just use "groovy truth" - ie:

if (AField && ! BField)

instead of what you have written. Empty strings and null both evaluate to false in that context.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

485 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you