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

# Apply transformer conditionally

> Executes a transformer when a condition is met.

export const FormField = ({property, label, required = false, diType, uiPatterns, children}) => {
  const patterns = Array.isArray(uiPatterns) ? uiPatterns : uiPatterns ? [uiPatterns] : [];
  return <div style={{
    margin: '1.5rem 0'
  }}>
      <div style={{
    display: 'flex',
    alignItems: 'baseline',
    flexWrap: 'wrap',
    gap: '0.5rem',
    marginBottom: '0.25rem'
  }}>
        <strong>{label}</strong>
        <span style={{
    fontSize: '0.7rem',
    fontWeight: 600,
    textTransform: 'uppercase',
    letterSpacing: '0.04em',
    color: required ? '#6241f5' : '#6b7280'
  }}>
          {required ? 'Required' : 'Optional'}
        </span>
      </div>

      <div>{children}</div>

      {diType || patterns.length > 0 ? <p style={{
    fontSize: '0.85rem',
    color: '#6b7280',
    marginBottom: 0
  }}>
          {diType ? <>
              See the <a href={`/references/${diType}`}>{diType}</a> reference.{' '}
            </> : null}
          {patterns.length > 0 ? <>
              Accepts a <a href={`/documentation/placeholders-and-patterns/patterns#${patterns[0]}`}>pattern</a>.
            </> : null}
        </p> : null}
    </div>;
};

Runs one set of transformers only when the conditions you define are met, and optionally a different set when they are not. This brings decision-making into your data flow, so you can react to what each entity actually contains. For example, you might mark an order as ready to ship when it is paid, and leave it unmarked when it is not. The branches are checked in order from top to bottom: the first one whose conditions match runs, and once a branch runs, the rest are skipped.

This documentation describes: [Schema](/schemas/transformer/conditional)

## Fields

<FormField property="filters" label="If all conditions are met" required diType="filter">
  The conditions that decide whether the main transformers run. Every condition you add here must be true for this branch to match. Each one checks something about the entity, such as whether a field has a certain value. See [Conditions](/references/filter) for what you can check.
</FormField>

<FormField property="transformers" label="Then apply transformers" required diType="transformer">
  The transformers to run when all the conditions above are met. They run in order, one after another. See [Transformers](/references/transformer) for the available options.
</FormField>

<FormField property="elseCases[].filter" label="Else if these conditions met" diType="filter">
  Extra branches that are only checked when the first set of conditions does not match. Each branch has its own conditions, set here, and its own transformer. They are checked top to bottom, and the first one that matches runs and stops the rest. Use this when you have several alternative cases to handle.
</FormField>

<FormField property="elseCases[].transformer" label="Else if apply transformer" diType="transformer">
  The transformer to run when this "else if" branch is the first one whose conditions match. See [Transformers](/references/transformer) for the available options.
</FormField>

<FormField property="elseTransformers" label="Else apply transformers" diType="transformer">
  The transformers to run when none of the branches above matched. Leave this empty to make the feature do nothing when no branch applies. See [Transformers](/references/transformer) for the available options.
</FormField>

## Sample data

This example marks an order as ready to ship when it is paid, and leaves it not ready when it is not.

| Field                     | Value                          |
| ------------------------- | ------------------------------ |
| If all conditions are met | `order.status` equals `paid`   |
| Then apply transformers   | Set `ready_to_ship` to `true`  |
| Else apply transformers   | Set `ready_to_ship` to `false` |

Input:

```json theme={null}
[
    { "order": { "id": 1001, "status": "paid" } },
    { "order": { "id": 1002, "status": "pending" } }
]
```

Output:

```json theme={null}
[
    { "order": { "id": 1001, "status": "paid" }, "ready_to_ship": true },
    { "order": { "id": 1002, "status": "pending" }, "ready_to_ship": false }
]
```

The first order is paid, so the "then" branch runs and sets `ready_to_ship` to `true`. The second order is pending, so the conditions fail and the "else" branch sets `ready_to_ship` to `false`.

```json Configuration theme={null}
{
  "prototype": "conditional",
  "parameters": {
    "filters": [
      {
        "prototype": "value-condition-v2",
        "parameters": {
          "accessor": {
            "prototype": "key",
            "parameters": { "root": "order", "keys": ["status"] }
          },
          "conditions": [
            { "prototype": "equals-adaptive", "parameters": { "value": "paid" } }
          ]
        }
      }
    ],
    "transformers": [
      {
        "prototype": "value-setter",
        "parameters": {
          "configurations": [
            { "key": "ready_to_ship", "value": true }
          ]
        }
      }
    ],
    "elseTransformers": [
      {
        "prototype": "value-setter",
        "parameters": {
          "configurations": [
            { "key": "ready_to_ship", "value": false }
          ]
        }
      }
    ]
  }
}
```
