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)=%%
Best Answer
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.
The function will return
True
if the field, irrespective of its type (text, number, boolean, date, etc), does not contain a value.