IsNullDefault
Returns a value, or a fallback when it is null. Runtime-proven on a live Marketing Cloud Engagement CloudPage — where the fallback was never reached and every empty-ish input returned the empty string instead.
Syntax
IsNullDefault(value, defaultValue) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
string | number | boolean | date | Yes | Value to test — returned unchanged whenever it is present |
defaultValue |
string | number | boolean | date | Yes | Fallback to return when the value is null — only reached in a Smart Capture form context |
Example
The shape it is built for is a Smart Capture form field, repopulating an input after a failed submit:
%%[
VAR @tier
SET @tier = RequestParameter("tier")
]%%
<input name="tier" value="%%=IsNullDefault(@tier, 'Basic')=%%">
Outside that context the fallback does not arrive. Requested without a tier parameter, the page rendered value="" — not Basic. Where a fallback really is needed, build it from a test that works everywhere:
%%=IIf(Empty(@tier), "Basic", @tier)=%%
Return value
string — the original value when it is present, otherwise the empty string on a CloudPage.
The domain is whatever the caller passes, so there is no set of literals to test for. The run rendered hello, three spaces, 0, false, a full date-time string and the empty string from this one function.
Behaviour
A present value comes back unchanged and unconverted. Whitespace survives verbatim, 0 renders as 0, and the string "false" comes back lowercase — distinguishable from the capitalised False that Empty renders.
A non-string argument is accepted in either position. IsNullDefault(Now(), "DEF") returned the full date-time string rather than aborting, and a number was accepted in the fallback position.
The fallback was never returned. Six distinct empty-ish inputs — undeclared variable, unset variable, the empty string, an absent request parameter, an attribute that does not exist, and the firstname profile token — each returned the empty string. The fallback literal appeared zero times in the entire run.
That agrees with both references rather than contradicting them. The official page scopes the function to Smart Capture forms from its first sentence, and the community guide states outright that it will not return a null-occurrence value in another context. The Smart Capture context cannot be reached from a plain page request, so the other half of that behaviour is untested here rather than disproven.
How the four Utility tests compare
The same inputs put through all four functions, on one page, in one run:
| Input | Empty |
IsNull |
IsNullDefault(x, "DEF") |
IIf(x, "T", "F") |
|---|---|---|---|---|
| undeclared variable | True | False | (empty) | F |
| declared, never set | True | False | (empty) | F |
"" |
True | False | (empty) | F |
" " |
False | False | ` ` | F |
0 |
False | False | 0 |
F |
"0" |
False | False | 0 |
F |
"false" |
False | False | false |
F |
"hello" |
False | False | hello |
F |
The third column is a pass-through with an empty string where the fallback was expected — and no error to signal it.
Show test script
%%[
VAR @b, @unset, @es, @sp, @z, @z0, @sf, @val
SET @b = RequestParameter("b")
SET @es = ""
SET @sp = " "
SET @z = 0
SET @z0 = "0"
SET @sf = "false"
SET @val = "hello"
/* known-good control: renders on every request, so a run of HTTP 422s
can be told apart from a broken deploy */
OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))
/* a name that was never declared */
IF @b == "d_und" THEN
OutputLine(Concat("--- d_und start ---"))
OutputLine(Concat("D_UND=[", IsNullDefault(@zzz_never_declared, "DEF"), "]"))
OutputLine(Concat("--- d_und done ---"))
ENDIF
/* declared with VAR, never assigned */
IF @b == "d_unset" THEN
OutputLine(Concat("--- d_unset start ---"))
OutputLine(Concat("D_UNSET=[", IsNullDefault(@unset, "DEF"), "]"))
OutputLine(Concat("--- d_unset done ---"))
ENDIF
/* the explicitly empty string */
IF @b == "d_es" THEN
OutputLine(Concat("--- d_es start ---"))
OutputLine(Concat("D_ES=[", IsNullDefault(@es, "DEF"), "]"))
OutputLine(Concat("--- d_es done ---"))
ENDIF
/* three spaces - returned verbatim, so the brackets show them */
IF @b == "d_sp" THEN
OutputLine(Concat("--- d_sp start ---"))
OutputLine(Concat("D_SP=[", IsNullDefault(@sp, "DEF"), "]"))
OutputLine(Concat("--- d_sp done ---"))
ENDIF
/* the number zero, as a variable and inline */
IF @b == "d_z" THEN
OutputLine(Concat("--- d_z start ---"))
OutputLine(Concat("D_Z=[", IsNullDefault(@z, "DEF"), "]"))
OutputLine(Concat("D_ZLIT=[", IsNullDefault(0, "DEF"), "]"))
OutputLine(Concat("--- d_z done ---"))
ENDIF
/* the string "0" */
IF @b == "d_z0" THEN
OutputLine(Concat("--- d_z0 start ---"))
OutputLine(Concat("D_Z0=[", IsNullDefault(@z0, "DEF"), "]"))
OutputLine(Concat("--- d_z0 done ---"))
ENDIF
/* the string "false" - lowercase, unlike the token Empty renders */
IF @b == "d_sf" THEN
OutputLine(Concat("--- d_sf start ---"))
OutputLine(Concat("D_SF=[", IsNullDefault(@sf, "DEF"), "]"))
OutputLine(Concat("--- d_sf done ---"))
ENDIF
/* a genuine value, as a variable and inline */
IF @b == "d_val" THEN
OutputLine(Concat("--- d_val start ---"))
OutputLine(Concat("D_VAL=[", IsNullDefault(@val, "DEF"), "]"))
OutputLine(Concat("D_VLIT=[", IsNullDefault("hello", "DEF"), "]"))
OutputLine(Concat("--- d_val done ---"))
ENDIF
/* a date value, and a number in the default position */
IF @b == "d_date" THEN
OutputLine(Concat("--- d_date start ---"))
OutputLine(Concat("D_DATE=[", IsNullDefault(Now(), "DEF"), "]"))
OutputLine(Concat("D_DEFNUM=[", IsNullDefault(@unset, 42), "]"))
OutputLine(Concat("--- d_date done ---"))
ENDIF
/* the form-field shape both references use in their examples; fetch
without a tier parameter in the query string */
IF @b == "d_rp" THEN
OutputLine(Concat("--- d_rp start ---"))
OutputLine(Concat("D_RP=[", IsNullDefault(RequestParameter("tier"), "Basic"), "]"))
OutputLine(Concat("--- d_rp done ---"))
ENDIF
/* an attribute that does not exist */
IF @b == "a_attr" THEN
OutputLine(Concat("--- a_attr start ---"))
OutputLine(Concat("D_ATTR=[", IsNullDefault(AttributeValue("zzNoSuchAttribute"), "DEF"), "]"))
OutputLine(Concat("--- a_attr done ---"))
ENDIF
/* a profile attribute outside a send */
IF @b == "s_prof" THEN
OutputLine(Concat("--- s_prof start ---"))
OutputLine(Concat("D_PROF=[", IsNullDefault(firstname, "DEF"), "]"))
OutputLine(Concat("--- s_prof done ---"))
ENDIF
]%%
Reaching for this as a general fallback returns the empty string instead of the supplied default, at HTTP 200 and with no error. The bug surfaces as a blank on the rendered page, which is easy to mistake for a data problem. Use IIf(Empty(x), fallback, x) outside Smart Capture.
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
- Empty — the test that actually separates missing from present on a page
- IsNull — the same null definition without the fallback argument
- IIf — pair it with
Emptyto build the fallback this function does not deliver - Official reference · ampscript.guide