The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

If condition based to a null field

utente
Giga Expert

Hi all,

I think that this question is very simple for an expert developer, but for me it generate a big confusion.

when i prepare an "if" [condition] inside a script based on an hypothetical field storen in a table of the system is better use:

  1. if  ( filed == '' )    { ... }
  2. if  ( field == null )    { ... } 
  3. if  ( field === null )    { ... }

 

Best Regards

Vincenzo

1 ACCEPTED SOLUTION

Deepak Ingale1
Mega Sage

So there are different ways to check if field value is null or undefined or false

 

1) If you want to look for undefined or null or nil or false, you can use JSUtil.nil(recordReference.fieldName)

2) If you are looking for null / nil check only, you can also use gs.nil() method

3) Already pointed in this thread 🙂

 

Hope above reply assist you now and in future !!!

View solution in original post

4 REPLIES 4

Deepak Ingale1
Mega Sage

Are you looking for valid field or field with valid value ( not null ? )

 

 

arielgritti
Kilo Sage

Hello

Maybe this can help you

You can use this if you are looking for a field's null value

 

find_real_file.png

 

I hope my answer has been useful

Ariel

PS: Please mark my answer correct or helpful if I have helped you. Thanks

Deepak Ingale1
Mega Sage

So there are different ways to check if field value is null or undefined or false

 

1) If you want to look for undefined or null or nil or false, you can use JSUtil.nil(recordReference.fieldName)

2) If you are looking for null / nil check only, you can also use gs.nil() method

3) Already pointed in this thread 🙂

 

Hope above reply assist you now and in future !!!

Inactive User14
Giga Contributor

Hi, nil() is good, ok but i write this simple function JS code. Enjoy.

//
// " ! " always returns false!
//
var fEmpty = function (vEmpty) {
if (typeof vEmpty === 'string') { vEmpty = vEmpty.trim(); } //remove spaces
if (!vEmpty) { return false }
else { return true }}
 
 
// Test
xx = new Array();
xx[0] = "";
xx[1] = null;
xx[2] = undefined;
xx[3] = NaN;
xx[4] = 0;
xx[5] = " ";
//xx[6]=
vfalse=false;
xx[7] = " ss ";
xx[8] = 12;
xx[9] = "aaa";
arr = ['a', 'b'];
function Student(n, a) {
this.name = n;
this.age = a; }
obj = new Student("RntPsc");
vtrue=true;
 
// Evidence
console.log(fEmpty(xx[0])); // false ""
console.log(fEmpty(xx[1])); // false null
console.log(fEmpty(xx[2])); // false undefined
console.log(fEmpty(xx[3])); // false NaN
console.log(fEmpty(xx[4])); // false 0
console.log(fEmpty(xx[5])); // false " "
console.log(fEmpty(xx[6])); // false xx[6] not defined
console.log(fEmpty(obj.age)); // false obj.age not defined
console.log(fEmpty(vfalse)); // false false
console.log("end true"); // end false
console.log(fEmpty(xx[7])); // true " ss "
console.log(fEmpty(xx[8])); // true 12
console.log(fEmpty(xx[9])); // true "aaa"
console.log(fEmpty(arr)); // true ['a', 'b']
console.log(fEmpty(obj.name));// true obj.name = "RntPsc"
console.log(fEmpty(vtrue)); // true true
console.log("end false"); // end true