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

0 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

361 views 0 6
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