Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Current.xxx returned string "null" in business rule

PhoenixMing0912
Giga Expert

Hi all,

I am using current.xxx or current.getValue("xxx") in business rule for getting a reference field.

The reference field was set to empty, however, I got a string "null" so that I cannot use some function to check if the field was empty, because a string "null" is also "has value".

How to check a reference field is empty in the business rule?

 

Regards,
Ming

7 REPLIES 7

DrewW
Mega Sage

There are a few ways you can check for this.  One is above, the others that I know are

if(!current.field){
   //Do work
}

if(current.getValue("field") != "null" && current.getValue("field") != ""){
  //Do work
}

PhoenixMing0912
Giga Expert

The root cause maybe in transform map "copy empty fields" option.

If this check box was checked, if empty value was set to a reference field, in business rule, current.xxx will return a value "null" string. This maybe a problem.

Anurag Tripathi
Mega Patron
Mega Patron

Try

if(JSUtil.notNil(current.XXX))

{

//do something

}

 

This checks for '', null and undefined

 

-Anurag

-Anurag