# Data Transformation Addon

The purpose of this block is to produce a transformed result based on the data from the source

and filters blocks.

This block can be used in conjunction with pagination and filters for the

source block.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-f070ee5dc929ff61d4f1a0ca55c5eaf2c8f94e47%2Fimage%20(833).png?alt=media" alt=""><figcaption></figcaption></figure>

## Usage

As shown in the example below, dataTransformationAddon blocks should be placed after

documentsSourceAddon and filtersAddon blocks.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-f65b96eb4c97c38c1b665a42fe62e21b72e353d0%2Fimage%20(834).png?alt=media" alt=""><figcaption></figcaption></figure>

## Properties

| Property Name        | Description                                                                                                                            | Example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Expression           | <p>A custom JavaScript</p><p>function that transforms</p><p>the existing source data</p><p>and returns it in a</p><p>custom format</p> | <p><code>function main(documents){</code></p><p><code>let sum = 0;</code></p><p><code>for(let i=0; i< documents.length; i++) {</code></p><p><code>sum+=</code></p><p><code>documents\[i].document.credentialSubject\[0].fiel</code></p><p><code>d0 +</code></p><p><code>d1;</code></p><p><code>documents\[i].document.credentialSubject\[0].fiel</code></p><p><code>}</code></p><p><code>return {</code></p><p><code>sum</code></p><p><code>}</code></p><p><code>}</code></p><p><code>done(main(documents));</code></p> |
| hideWhenDiscontinued | Check if the button should be hidden when policy is discontinued                                                                       | Checked/Unchecked                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

## API

The API for the dataTransformationAddon uses the GET method

Example response to a GET request that returns the sum of 2 fields in a custom format:

```
{
"sum": 10
}
```

The request can be fulfilled through both endpoint

*`/api/v1/policies/{policyId}/blocks/{blockId}`*

and

*`/api/v1/policies/{policyId}/tag/{blockTag}/blocks`*
