Scenario
This guide covers two fundamental use cases:
- Form Mode: Copy a value from a single source (header, body field, query parameter) to another variable.
- Template Mode: Combine values from multiple sources to create a single variable.
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
| Field | Value |
|---|
| Build Mode | Form |
| Source | Header → X-Tenant-Id |
| Target | Custom Variable → tenantId |
| Default Value | default-tenant |
| Required | No |
Result
| Incoming Header | tenantId Variable Value |
|---|
X-Tenant-Id: acme-corp | acme-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
| Field | Value |
|---|
| Build Mode | Form |
| Source | Request Body → JSON Path $.userId |
| Target | Custom Variable → currentUserId |
| Default Value | anonymous |
| Required | No |
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
| Field | Value |
|---|
| Build Mode | Template |
| Template | Template above |
| Target | Custom Variable → auditEntry |
| Default Value | unknown | 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.