It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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 Leader Jan 21, 2020 • edited

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

This should satisfy the requirement.

Thanks again Leo!

@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 Leader Jan 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 

@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 Leader Jan 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
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you