Testing for null or empty values

Null is a concept that generally means a value is unknown (programming languages) or missing (database). In Medallia Experience Cloud, nulls often cause problems in K-fields, surveys, and Auto importer processors. Basically, any expression where a value is expected, but because Experience Cloud does not know what to do, it keeps running, often generating a Null pointer exception error.

Testing strings in JavaScript

JavaScript has a short-hand way of testing for string values for null or empty strings:

if (!value) {
  return 'MISSING VALUE';
}

However, the above JavaScript expression is true in other cases, depending on the data type, including:

  • Null
  • Undefined or NaN
  • Empty string ("")
  • 0 (for numeric values)
  • False (for Boolean values)

The easiest way to test for true null is like this:

if (value === null)
return 'MISSING VALUE';

However, the expression above does not catch these other null-like conditions:

  • Undefined or NaN (results is undefined, such as division by zero)
  • Empty string ("")

To test for null, empty strings, and undefined:

if (value === undefined || value === '' || value === null)

Auto importer

Auto importer specifications can use the hasContent function checks for null, undefined, and empty strings. In this example the expression returns the string MISSING VALUE when the value is empty:

if !hasContent (value)
return 'MISSING VALUE' ;