IIf
→ anyReturns one of two values based on a boolean condition. Inline if — similar to the ternary operator.
Available in:
Email
CloudPage
Automation
Triggered Send
Syntax
Platform.Function.IIf(condition, trueValue, falseValue)
3 arguments
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
condition |
boolean | Yes | Boolean expression to evaluate |
trueValue |
any | Yes | Value returned if condition is true |
falseValue |
any | Yes | Value returned if condition is false |
Examples
var greeting = Platform.Function.IIf(isLoggedIn, "Welcome back!", "Please log in.");
Write(greeting);
// Equivalent ternary:
var greeting2 = isLoggedIn ? "Welcome back!" : "Please log in.";
In SSJS, the ternary operator (? :) is preferred over IIf — use IIf only for consistency with existing AMPscript patterns.