Forums

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

How to use a blank field as a condition in script runner?

Jeremy Jedlicka
Contributor
March 15, 2022

Any help would be appreciated with this.

I'm using script runner to prepopulate a field if the field is currently empty.

I have:

def value = getFieldByName('Acceptance Criteria').value
def field = getFieldByName('Acceptance Criteria')

to get the value of the field Acceptance Criteria

I should then be able to write:

if(value == null) {
         field.setFormValue('Not Null')
}

But that's not working

 

To try and figure out why its not working I wrote this:

def value = getFieldByName('Acceptance Criteria').value
def field = getFieldByName('Description')
field.setFormValue(value)

if(value != null) {
field.setFormValue('Not Null')
}

 

So if the field Acceptance Criteria is not null the Description field would populate with "Not Null"

That works.  Unfortunately it also populates Not Null when the Acceptance Critieria field is empty. 

So even though the field is empty the system does not recognize it as null.

 

Anyone have any idea how to fix this? 

2 answers

1 vote
Jeremy Jedlicka
Contributor
March 15, 2022

I figured it out for anyone looking at this in the future.

I needed to change (value == null) to (value == '')

Apparently, null doesn't mean empty.

0 votes
Helmy Ibrahim _Adaptavist_
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.
March 15, 2022

Hi Jeremy,

It is better to use Groovy Truth to do a null check as it is simpler:

if (!value) {
field.setFormValue('Null')


// or

if (value) {
field.setFormValue('Not Null')

Cheers,
Helmy

Suggest an answer

Log in or Sign up to answer