AMPscript IIf (Next)
Pick one of two values from a condition with AMPscript IIf in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including which plain values count as true and the evaluation of both branches.
Syntax
IIf(expression, trueValue, falseValue) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
expression |
boolean | Yes | Condition to evaluate — in Next some non-boolean values select the true branch ("hello", "0", whitespace) and others the false one ("", 0, "false") |
trueValue |
string | number | boolean | date | Yes | Value returned when true; evaluated in Next even when false is selected |
falseValue |
string | number | boolean | date | Yes | Value returned when false; evaluated in Next even when true is selected |
Example
%%[ SET @firstName = "" ]%%
Hello %%=IIf(Empty(@firstName), "there", @firstName)=%%,
Renders Hello there,.
A comparison works in both directions:
%%=IIf(1 == 1, "yes", "no")=%%
Renders yes; with 1 == 2 the call gives the false branch.
Return value
string — the selected branch, passed through as it is.
The result is whatever the branches hold, so there is no fixed set of values. Calls in Next rendered T, F, 42 and a date-time.
Behaviour
Comparisons and boolean functions work as conditions. 1 == 1 picks the true branch and 1 == 2 the false one. Empty(@var) works too, also negated as NOT Empty(@var).
== and != ignore case on strings. IIf("abc" == "ABC", "eq", "ne") gives eq, two variables holding Hello and hello compare as equal, and "abc" != "ABC" is false; "abc" == "abd" is still false. Engagement compares with regard to case, so a condition that tells ABC from abc there does not in Next.
Some non-empty strings count as true. Used directly as the condition, a variable holding "hello", "0" or whitespace selects the true branch (written as a literal, the run of spaces reaches AMPscript as a single space, because the render collapses runs of spaces).
These count as false: an undeclared variable, a variable declared but never set, the empty string, the number 0 and the string "false".
| Condition variable | IIf(@x, "T", "F") |
|---|---|
| undeclared | F |
| declared, never set | F |
"" |
F |
" " (whitespace) |
T |
0 |
F |
"0" |
T |
"false" |
F |
"hello" |
T |
Testing a value directly is therefore not a reliable presence check. Use Empty(@x) as the condition.
Branch values are not converted. IIf(1 == 1, 42, 7) gives 42. A date in the selected branch comes out as 2026-11-22T20:27:28: ISO form with a T between date and time.
Both branches are evaluated. With RaiseError in the branch that is not selected, in either direction, the email saves but its preview fails with HTTP 500. Do not rely on the condition to keep a failing or costly call from running.
Show Next test script
<!-- Marketing Cloud Next test script for IIf. 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=[yes] got=[%%=IIf(1==1,"yes","no")=%%]</p>
<p>c2 expect=[F] got=[%%=IIf(1 == 2, "T", "F")=%%]</p>
<p>c3 expect=[42] got=[%%=IIf(1 == 1, 42, 7)=%%]</p>
<p>c4 expect=[T] got=[%%[ SET @r2ies = "" ]%%%%=IIf(Empty(@r2ies),"T","F")=%%]</p>
<p>c5 expect=[F] got=[%%[ SET @r2ines = "" ]%%%%=IIf(NOT Empty(@r2ines),"T","F")=%%]</p>
<p>c6 expect=[F] got=[%%=IIf(@r2i_never_declared,"T","F")=%%]</p>
<p>c7 expect=[F] got=[%%[ VAR @r2iu ]%%%%=IIf(@r2iu,"T","F")=%%]</p>
<p>c8 expect=[F] got=[%%[ SET @r2ie = "" ]%%%%=IIf(@r2ie,"T","F")=%%]</p>
<p>c9 expect=[T] got=[%%[ SET @r2isp = " " ]%%%%=IIf(@r2isp,"T","F")=%%]</p>
<p>c10 expect=[F] got=[%%[ SET @r2iz = 0 ]%%%%=IIf(@r2iz,"T","F")=%%]</p>
<p>c11 expect=[T] got=[%%[ SET @r2iz0 = "0" ]%%%%=IIf(@r2iz0,"T","F")=%%]</p>
<p>c12 expect=[F] got=[%%[ SET @r2isf = "false" ]%%%%=IIf(@r2isf,"T","F")=%%]</p>
<p>c13 expect=[T] got=[%%[ SET @r2ival = "hello" ]%%%%=IIf(@r2ival,"T","F")=%%]</p>
<p>c14 expect=[2026-11-22T20:27:28] got=[%%=IIf(1 == 2,"no",Now())=%%]</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) -->
%%=IIf(Empty(""), "T", "F")=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=IIf(1 == 1,"T",RaiseError("r2-iif-false-branch-evaluated"))=%%
<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=IIf(1 == 2,RaiseError("r2-iif-true-branch-evaluated"),"F")=%%
Differs from official docs
- Both branches are evaluated. The docs describe
IIfas returning one of two values and do not mention that the other branch runs. In Next aRaiseErrorin the branch that is not selected makes the preview fail with HTTP 500. Card - Plain strings as the condition follow undocumented rules. The docs type the condition as a string without saying which values are true. In Next
"hello","0"and whitespace select the true branch;"",0and"false"the false one. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
In Engagement every plain value selects the false branch; in Next a non-empty string such as "hello", "0" or whitespace selects the true branch (T). Engagement evaluates only the selected branch, so a RaiseError in the other branch is harmless; in Next the same email fails to render. Engagement’s == and != compare strings with regard to case; in Next they ignore case (IIf("abc" == "ABC", "eq", "ne") gives eq). Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- Empty — the condition to use for a presence check
- IsNull — another boolean test
- RaiseError — runs even in the branch that is not selected
- Official reference