Skip to main content

Scenario

This guide covers two fundamental use cases:
  1. Form Mode: Copy a value from a single source (header, body field, query parameter) to another variable.
  2. Template Mode: Combine values from multiple sources to create a single variable.

Example 1: Copy a Value with Form Mode

In this example, the X-Tenant-Id header value is copied to a custom variable. If the header is missing, default-tenant is assigned as the default value.

Row Configuration

FieldValue
Build ModeForm
SourceHeader → X-Tenant-Id
TargetCustom Variable → tenantId
Default Valuedefault-tenant
RequiredNo

Result

Incoming HeadertenantId Variable Value
X-Tenant-Id: acme-corpacme-corp
(header missing)default-tenant

Example 2: Copy a Body Field

A userId field from the request body is read in Form mode and stored in a custom variable.

Row Configuration

FieldValue
Build ModeForm
SourceRequest Body → JSON Path $.userId
TargetCustom Variable → currentUserId
Default Valueanonymous
RequiredNo

Example 3: Merge Multiple Sources with Template Mode

In this example, a username from the request header, an operation type from the body, and the system date-time are combined to create a single audit entry variable.

Template

#{header.X-User-Name} | #{body.$.operationType} | #{context.system.dateTime}

Row Configuration

FieldValue
Build ModeTemplate
TemplateTemplate above
TargetCustom Variable → auditEntry
Default Valueunknown | unknown | -

Result

For a sample request (X-User-Name: john, body {"operationType":"update"}):
john | update | 2026-02-20T10:35:48.000Z

Example 4: Building a Composite Identifier

Combining two fields from the request body and context information to create a unique transaction ID:

Template

#{body.$.orderId}-#{body.$.customerId}-#{context.message.correlationId}

Result

ORD-001-CUST-789-8260e8b4-29d7-479a-8266-5dbb29c0d0fa

Best Practice: Use Form mode when copying from a single source. Template mode should be used when merging or transforming values; it avoids unnecessary parsing overhead.
For the full list of variable sources, see the template syntax section on the Message Builder policy page.