> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Value Copy and Merging

> You can copy a value from a source variable to a target variable using Form mode, and combine values from multiple sources into a single variable using Template mode.

## 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

| 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
```

***

<Tip>
  **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.
</Tip>

<Note>
  For the full list of variable sources, see the template syntax section on the [Message Builder](/en/develop/policies/message-builder#template-syntax) policy page.
</Note>
