Skip to main content

Scenario

In some cases, the value of a variable depends on the content of the incoming request. There are two approaches to conditional value assignment:
  1. Row Condition: Execute the row only when a specific condition is met.
  2. JEXL Ternary Expression: Decide which value to assign within a single row.

Approach 1: Conditional Row Execution

Row conditions allow you to execute a row only when a specific condition is true. For the “false” case, set the default value as the fallback.

Example: Different Label Based on Status

Assign ACTIVE if the status field in the request body is active, otherwise assign PASSIVE. Row 1 — Default value (always runs): Row 2 — Override when condition is met:

Result


Approach 2: JEXL Ternary Expression

A ternary expression makes the decision within a single row using the condition ? trueValue : falseValue syntax.

Example: Operation Type Based on HTTP Method

Result


Approach 3: Conditional JSON Part Generation

Generating an optional JSON object conditionally is one of the most powerful use cases. This is achieved by combining row conditions with custom variables.

Scenario

Include a metadata object in the body only if the type field in the request body is premium. Row 1 — Default: empty JSON string: Row 2 — Override with row condition: Row 3 — Final body template:
Do not wrap #{metadataBlock} in quotes in the final template. Since the variable already contains valid JSON, adding quotes would turn it into a string, breaking the JSON structure.

Result


When using row conditions with custom variables, define the default value in the first row (without a condition). This way, if no condition matches, the variable will still have a safe default value.