# Fallback transform function

## Introduction

The `fallback` transform function is used to provide a value to be used if a source field to be mapped is empty. For example, consider the following payload:

```json
[
    {"ref1": "10001","ref2":"10001"},
    {"ref1":"20001", "ref2":"20001"},
    {"ref1": "10001", "ref2":"10001"},
    {"ref1": "30001", "ref2":"30001"},
    {"ref1": "10001", "ref2":"10001"},
    {"ref1": "", "ref2":"40001"}
]
```

Now, suppose that you are syncing the `ref1` field to a target system that cannot accept empty values. Given that the final item in this payload is empty, a process flow would fail.&#x20;

One way to prevent this is to provide a fallback value - for example, `00000`. In this case, our incoming payload would be output as follows:

```json
[
    {"ref1": "10001","ref2":"10001"},
    {"ref1":"20001", "ref2":"20001"},
    {"ref1": "10001", "ref2":"10001"},
    {"ref1": "30001", "ref2":"30001"},
    {"ref1": "10001", "ref2":"10001"},
    {"ref1": "00000", "ref2":"40001"}
]
```

Using the `fallback` transform function, you can define fallback values using:

* [a static value](#adding-a-fallback-transform)
* [a flow variable value](#adding-a-fallback-transform)
* [a payload field value](#using-another-payload-field-for-fallback-values)

## Adding a fallback transform&#x20;

{% stepper %}
{% step %}
**Edit map shape settings**

In your process flow, access settings for your map shape. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F21qb17okzN7grKQmceQp%2Ffallback%20transform%201.png?alt=media&#x26;token=1b31cf6c-94e7-425e-81d0-694487580e70" alt="" width="356"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Access transforms for the required mapping**

Locate the mapping rule that you want to update (or add a new mapping rule), then click the `transform` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIF49FFPEvA1O5g7iRgCR%2Ffallback%20transform%202.png?alt=media&#x26;token=95543d01-5655-4f19-ada6-917967f1e80b" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add a new transform**&#x20;

Click the `add transform` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCEaSTBmbh7iHqhUb004k%2Ffallback%20transform%203.png?alt=media&#x26;token=966e05d0-10a7-4052-b2a0-e738ee3af01f" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Select the fallback transform function**&#x20;

Click in the `name` field to access a list of all available transform functions, then select `fallback` from the `other` category. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FgYK8KpzAtInGmRjD0jBv%2Ffallback%20transform%204.png?alt=media&#x26;token=6a22c1cc-2dd2-4849-a717-5161e7a042e4" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Enter your required fallback value**

In the `fallback` field, enter the value to be used if the mapped source field is empty. You can enter a static value - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FEnjhqJ7EhBeBMkor4D8k%2Ffallback%20transform%205.png?alt=media&#x26;token=be5cbd22-fd5f-4bfd-b072-b60a5929a3df" alt=""><figcaption></figcaption></figure></div>

Alternatively, you can pass in the value of a flow variable, using [flow variable syntax](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables) - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FGZWz8FWQJLxLPnnCM3he%2Ffallback%20transform%207.png?alt=media&#x26;token=63de520c-dac6-4eb2-9487-5fa1d5258ec9" alt=""><figcaption></figcaption></figure>

You can also fall back to the value of another payload field however, this works slightly differently and you don't enter anything here. For details, please see [Using another payload field as a fallback value](#using-another-payload-field-as-a-fallback-value).&#x20;
{% endstep %}

{% step %}
**Confirm the source field to be transformed**

Click the `add field` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FQOgviwrlgFrsFxx69Mft%2Ffallback%20transform%208.png?alt=media&#x26;token=276a72e5-b1d3-4d83-b176-209c6aa67298" alt=""><figcaption></figcaption></figure></div>

...then click in `source fields` and select the source field to be used for this transform:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FeeKtMFBfm0QLtfJGgqYJ%2Ffallback%20transform%209.png?alt=media&#x26;token=00cc04bf-5648-40f5-8809-305568d38ccb" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Confirm transform settings**

Accept your changes (twice), then save the transform.&#x20;
{% endstep %}
{% endstepper %}

## Using another payload field for fallback values

Consider the following payload:

```json
{"ref1": "", "ref2":"40001","ref3":"40001"}
```

Suppose we need to map `ref1` to a target field named `reference`. There's no value for `ref1` but we do have a value for `ref2`, which could be used as fallback. Now consider another payload for the same scenario:

```json
{"ref1": "", "ref2":"","ref3":"40001"}
```

There's no value for `ref1` or `ref2` - but we do have a value for `ref3`, which could be used as fallback.

You can specify one or more fields from the incoming payload(s) to be checked for a fallback value. To do this, follow the steps below.

{% stepper %}
{% step %}
**Edit map shape settings**

In your process flow, access settings for your map shape. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F21qb17okzN7grKQmceQp%2Ffallback%20transform%201.png?alt=media&#x26;token=1b31cf6c-94e7-425e-81d0-694487580e70" alt="" width="356"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Define a mapping rule using all possible source fields**

Add a mapping rule in the usual way, with the required source and target fields. For example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FLy5LKRJbAg3rqvsLqWWl%2Ffallback%20transform%202a.png?alt=media&#x26;token=61411a61-57f9-4dce-8938-349eab86fcf7" alt=""><figcaption></figcaption></figure>

Then click anywhere in the source field:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn9EnRjvMAW1satzs2EEv%2Ffallback%20transform%202b.png?alt=media&#x26;token=47828f0d-ffe6-4492-a7e0-aaa6e50032c8" alt=""><figcaption></figcaption></figure>

...and choose to add another source field - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F8HwwD6wxUVen0ya2qedj%2Ffallback%20transform%202c.png?alt=media&#x26;token=6df83e80-38d0-42e1-83d6-e1d5651948de" alt=""><figcaption></figcaption></figure>

Click anywhere in the new source field:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FaBUFU3GwEC5oFaOvuRZp%2Ffallback%20transform%202d.png?alt=media&#x26;token=db0234f6-618f-4acf-b114-094bdcddcf56" alt=""><figcaption></figcaption></figure>

...and enter or select a field that can be checked for a fallback value - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FwmyHpgsqFXVgJOaT9Kyd%2Ffallback%20transform%202e.png?alt=media&#x26;token=572afd67-e3c0-4669-a646-228273308ebd" alt=""><figcaption></figcaption></figure>

Accept the new field to exit back to the mapping rule - now you have two source fields mapped to the target:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FrGBNbQEgdoYLnLsTe6FK%2Ffallback%20transform%202f.png?alt=media&#x26;token=5ec17dfa-c364-4747-b7d4-0c0c065bfeae" alt=""><figcaption></figcaption></figure>

If required, you can add additional 'fallback' source fields in the same way.
{% endstep %}

{% step %}
**Access transforms for the mapping rule**

Click the `transform` button for this mapping rule. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fux77s9fS2eHwVq5mhGaT%2Ffallback%20transform%203a.png?alt=media&#x26;token=cc14e6a3-dcb2-472c-8a1e-483a01adbd7c" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add a new transform**&#x20;

Click the `add transform` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCEaSTBmbh7iHqhUb004k%2Ffallback%20transform%203.png?alt=media&#x26;token=966e05d0-10a7-4052-b2a0-e738ee3af01f" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Select the fallback transform function**&#x20;

Click in the `name` field to access a list of all available transform functions, then select `fallback` from the `other` category. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FgYK8KpzAtInGmRjD0jBv%2Ffallback%20transform%204.png?alt=media&#x26;token=6a22c1cc-2dd2-4849-a717-5161e7a042e4" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add the primary source field to be used**

Click the `add field` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9WauBjeYlzFAWNrE1KRG%2Ffallback%20transform%204a.png?alt=media&#x26;token=81292864-13ce-46c8-8eac-cd67e5691ed9" alt=""><figcaption></figcaption></figure></div>

...then click in `source fields` and select the source field to be used for this transform as a priority - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Ffv8kehTsvyONCDqVXaKf%2Ffallback%20transform%2010.png?alt=media&#x26;token=53aa128e-ab07-4f12-aaa5-820b53efa4df" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
All source fields that you added in step 2 are available for selection.&#x20;
{% endhint %}

Select the source field that should be checked for a value first, and accept this change. The field is added as the first to be transformed - you can now add the remaining source fields in the sequence you want them to be checked for a fallback value:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FGVvcumter4KyuIC9aWln%2Ffallback%20transform%204b.png?alt=media&#x26;token=3c6d116f-0f26-437d-a74a-30d87a5e2099" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Confirm transform settings**

Having added all source fields for this mapping rule, accept your changes - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FOORob8ktrIUGXnNGwsVo%2Ffallback%20transform%204c.png?alt=media&#x26;token=ad997dc6-e2ed-420c-be0f-0e68f0505047" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}
