3

Does the IsNull AMPscript function actually work?

I'm trying to figure out a scenario where it will actually return true. Here's what I've tried:

Test 1

%%[
var @rows
set @rows = LookupRows("July member promo","Member",1) /* returns 0 rows */
]%%

%%=IsNull(@rows)=%%

Result 1

False

Test 2

%%[ var @rows ]%%

%%=IsNull(@rows)=%%

Result 2

False

Test 3

Surely this must work as AttributeValue will return null if the attribute does not exist...

%%[
var @field
set @field = AttributeValue("a field that does not exist")
]%%

%%=IsNull(@field)=%%

Result 3

False

IsNull versus Empty

And while I'm on the topic, if this function does actually return a correct result, then what's the difference between it and the Empty function? The Empty function returns to True if the expression is null or empty:

%%[
var @field
set @field = AttributeValue("a field that does not exist")
]%%

%%=Empty(@field)=%%
1
  • 1
    I was going to say that it may be used to detect the condition when a variable is not defined, yet referenced. That doesn't work either. Feb 13, 2018 at 18:56

1 Answer 1

5

The IsNull AMPscript function only works with Data Extension fields, where if the field does not contain a value, then the function will evaluate to True.

For example, In the example below, there is no value for the "First Name" Data Extension field.

%%[
var @field
set @field = Lookup("Test DE","First Name","ID","ABC123")
]%%

%%=IsNull(@field)=%%

The function will return True if the field, irrespective of its type (text, number, boolean, date, etc), does not contain a value.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .