Forums

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

Behaviours getValue() data return on freetext - conditional compare issue

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2020

I have a behavior I am attempting to only set form default value on if the form is empty. In the intialiser I have an if statement checking the freetext field for a value. I've tried about every combination of logic to check the field for data and I keep getting unexpected results.

What is the return on a free text field? For error checking I've added HelpText of the value being read in from the field using getValue() and I am consistently seeing "null" being returned even when there is data in the field.

What would be code used to check for an empty free text field? I feel like this rudimentary as I use it all over in other places scripts and behaviors, does the initialiser behave differently?

I've tried booleon comparison, string comparison, and nothing seems to be working well.

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Champion
January 21, 2020

Hi @Steven Mustari,

This seems to be a known issue with Behaviour's initialiser,

as a workaround you can add a field level behaviour to fix this

def field = getFieldByName("Field Name")

if (!field.getValue()) {
field.setFormValue("Default Value")
}

  

BR,

Leo

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2020

This should satisfy the requirement.

Thanks again Leo!

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2020

@Leo 

Well sort of, unfortunately, it wont let me submit a blank form. I need this to only run once. Could I trick it some how to only run one time when the field loads with out using the initialiser section?

Leo
Community Champion
January 22, 2020

Hi @Steven Mustari,

I don't think there is a way to add condition like this. but below workaround would meet your requirement if not 100% at least 80%

Instead of adding this behaviour for a needed field, add/map this behaviour to "Project" field so that this script will run only when create form loads

and it won't run until unless you change Project field value

Normally I map Issue type as I need different values based on issue types but for your requirement Project field should be appropriate one

 

BR,

Leo 

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2020

@Leo 

So in essence any field mapped will run one time when the form loads, and then will run again when that field is interacted with?

If I understand this correctly, you've provided me with some excellent insight for future configs.

Regards,
Steven

Leo
Community Champion
January 23, 2020

exactly, behaviour will run only when mapped field is affected with change(s)

Like Steven Mustari likes this

Suggest an answer

Log in or Sign up to answer