Verification in progress Test scripts included

Syntax

Empty(@variable)  →  boolean
1 argument — exactly

Parameters

Name Type Required Description
variable variable Yes An AMPscript variable; a literal or a nested function call in this slot makes Next reject the email at save

Next only takes a variable here. Assign a literal or a function result to a variable first, then test the variable.

Example

%%[ SET @firstName = "" ]%%
Hello %%=IIf(Empty(@firstName), "there", @firstName)=%%,

Renders Hello there,. Pairing it with IIf is the usual way to use the result.

Written straight into the content, the result is lowercase:

%%[ SET @code = "x" ]%%
%%=Empty(@code)=%%

Renders false.

Return value

boolean — true when the variable is missing or blank, false otherwise.

Both values are written in lowercase. In a condition the result compares equal to the boolean true and also to the string "True", so both comparison styles work.

Behaviour

Only a variable is accepted. An email containing Empty(""), Empty("x"), Empty(0) or Empty(Now()) cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”, pointing at the call. The same applies when Empty with a literal is nested in another function, such as IIf(Empty(""), "T", "F").

Three states count as empty: a variable set to the empty string, a variable declared with VAR but never set, and a name that was never declared. All three render true.

Whitespace is a value. A variable holding whitespace renders false (written as a literal, the run of spaces reaches AMPscript as a single space, because the render collapses runs of spaces).

0, "0" and "false" are values too. Each of them, held in a variable, renders false, as does "hello".

Attributes, request parameters and subscriber fields were not tested in Next, so whether a missing one counts as empty there is open.

Show Next test script
<!-- Marketing Cloud Next test script for Empty. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[true] got=[%%=Empty(@zzz_never_declared)=%%]</p>
<p>c2 expect=[false] got=[%%[ SET @r2ef0 = "x" ]%%%%=Empty(@r2ef0)=%%]</p>
<p>c3 expect=[matches-true] got=[%%[ SET @r2eq1 = "" IF Empty(@r2eq1) == true THEN SET @r2eq1r = "matches-true" ELSE SET @r2eq1r = "no-match" ENDIF ]%%%%=v(@r2eq1r)=%%]</p>
<p>c4 expect=[matches-True-string] got=[%%[ SET @r2eq2 = "" IF Empty(@r2eq2) == "True" THEN SET @r2eq2r = "matches-True-string" ELSE SET @r2eq2r = "no-match" ENDIF ]%%%%=v(@r2eq2r)=%%]</p>
<p>c5 expect=[true] got=[%%[ VAR @r2eu ]%%%%=Empty(@r2eu)=%%]</p>
<p>c6 expect=[true] got=[%%[ SET @r2ees = "" ]%%%%=Empty(@r2ees)=%%]</p>
<p>c7 expect=[false] got=[%%[ SET @r2esp = "   " ]%%%%=Empty(@r2esp)=%%]</p>
<p>c8 expect=[false] got=[%%[ SET @r2ez = 0 ]%%%%=Empty(@r2ez)=%%]</p>
<p>c9 expect=[false] got=[%%[ SET @r2ez0 = "0" ]%%%%=Empty(@r2ez0)=%%]</p>
<p>c10 expect=[false] got=[%%[ SET @r2esf = "false" ]%%%%=Empty(@r2esf)=%%]</p>
<p>c11 expect=[false] got=[%%[ SET @r2eval = "hello" ]%%%%=Empty(@r2eval)=%%]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the save is rejected (HTTP 400) -->
%%=Empty("")=%%

<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=Empty("x")=%%

<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=Empty(0)=%%

<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=Empty(Now())=%%

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also