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

# Using Functions

## Overview

Paragon's Functions are built-in cloud functions that provide a powerful way to add custom logic to your workflows. You can use functions to transform or compute data, or even to perform more complex operations within workflows that you might otherwise need to write server-side code for. Paragon functions support Javascript (ES7) and provide access to select npm modules.

<Card title="JavaScript Libraries" href="/resources/javascript-libraries" horizontal />

To add a function to your workflow, click the "+" button in the workflow canvas and choose the Function step from the sidebar.

<Frame>
  <img src="https://mintcdn.com/paragon/lKoo2WTuuveEy7P1/assets/adding-a-function-step-in-the-workflow-editor.png?fit=max&auto=format&n=lKoo2WTuuveEy7P1&q=85&s=9e25dd82d235769ba17e6482a7dda3e9" alt="" width="1126" height="810" data-path="assets/adding-a-function-step-in-the-workflow-editor.png" />
</Frame>

## Defining function parameters

You can pass any data from upstream steps into your Function as parameters using the key-value table under "What data should be passed in as parameters?". Under "Key", you can give your variable a name and under "Value" you can insert a variable from the variable menu by clicking the dropdown button.

## Writing function code

You can write your custom code in the `yourFunction()` function, which accepts any valid Javascript (ES7). Any data that you `return` from this function can then accessed by downstream steps in your workflow.

You can access parameters defined in the key-value table above by referencing `parameters.<parameter_name>` within `yourFunction()`. For example, a parameter whose key is `email` can be accessed in the function by referencing `parameters.email`.

<Frame>
  <img src="https://mintcdn.com/paragon/867oBBVpxd2C3zc4/assets/Writing%20function%20code%20in%20Paragon.gif?s=bce4a51cade921224519aa1c4fc3d364" alt="" width="1126" height="690" data-path="assets/Writing function code in Paragon.gif" />
</Frame>

## Using NPM modules in functions

Paragon provides access to [certain npm modules](/resources/javascript-libraries) that can be used within functions. Here's an example of how you can access the `uuid` npm module within a function.

```js JavaScript theme={null}
function yourFunction(parameters, libraries) {
  // Generate a uuid with the uuid Javascript library
  const uuid = libraries.uuid;
  const id = uuid.v4();
  return id;
}
```

Note that you'll need to add the `libraries` parameter to `yourFunction()`. If your function needs to work asynchronously, you can declare it `async`.

<Frame>
  <img src="https://mintcdn.com/paragon/867oBBVpxd2C3zc4/assets/Using%20npm%20modules%20in%20functions%20in%20Paragon.gif?s=d8105d0d9f55ab7b08181e5966314aab" alt="" width="1200" height="920" data-path="assets/Using npm modules in functions in Paragon.gif" />
</Frame>

You can find the full list of supported npm modules in our [Javascript Libraries Catalog](/resources/javascript-libraries). If you don't see the module that you're looking for, [let us know](mailto:team@useparagon.com) and can usually add it for you.

## Using Field Mappings in functions

If you have configured a [Field Mapping User Setting](/connect-portal/field-mapping) for your integration, you can reference the mapping object in a Function step and use the built-in `paragonUtils` library to programmatically transform data between your application format and the integration format.

This is useful when you need more control over the transformation process than the built-in "Apply field mapping" option on triggers provides — for example, when transforming arrays of objects, applying additional logic during the mapping, or chaining mappings with other operations.

### Passing a field mapping to your function

<Frame>
  <img alt="Selecting field mapping variable" src="https://mintcdn.com/paragon/3mNof4p8xpGmlkD6/assets/function-step-field-mapping-selection.gif?s=76f7cf64976f9c64ced4a025ff2a5cfd" width="400" data-path="assets/function-step-field-mapping-selection.gif" />
</Frame>

To use a field mapping in a Function step, pass it as a parameter:

1. In your Function step, add a parameter (e.g. `fieldMapping`).
2. Click the dropdown for the parameter value, navigate to **Connect Portal User Settings**, and select the **Mapping Configuration** for your field mapping.
3. You can then use the field mapping configuration value as `parameters.fieldMapping` in your Function step.

   Pass it to `paragonUtils.mapIntegrationObjects` or `paragonUtils.mapApplicationObjects` to apply the mapping to another value.

### Transforming data with `paragonUtils`

The `paragonUtils` library provides two functions for transforming data using a field mapping configuration:

<Tabs>
  <Tab title="mapIntegrationObjects">
    Transforms an array of **integration objects** into **application objects** using the field mapping. Use this when you receive data from an integration and need to convert it to your application's format.

    <Frame>
      <img alt="mapIntegrationObjects function step" src="https://mintcdn.com/paragon/3mNof4p8xpGmlkD6/assets/function-mapIntegrationObjects.png?fit=max&auto=format&n=3mNof4p8xpGmlkD6&q=85&s=d2c68df33f85e70943d2dc38dce82286" width="400" data-path="assets/function-mapIntegrationObjects.png" />
    </Frame>

    **Parameters:**

    * `mapping` — The field mapping configuration object passed as a parameter from Connect Portal User Settings.
    * `integrationObjects` — An array of integration objects to transform.

    **Returns:** An array of application objects with fields renamed according to the mapping.

    ```js theme={null}
    function yourFunction(parameters, libraries) {
      const { paragonUtils } = libraries;
      const { fieldMapping, integrationObjects } = parameters;

      const applicationObjects = paragonUtils.mapIntegrationObjects(
        fieldMapping,
        integrationObjects
      );

      return { applicationObjects };
    }
    ```

    For example, if your field mapping maps a property `Subject` (integration field) to `title` (application field), an input of `[{ "Subject": "Buy groceries" }]` would produce `[{ "title": "Buy groceries" }]`.
  </Tab>

  <Tab title="mapApplicationObjects">
    Transforms an array of **application objects** into **integration objects** using the field mapping. Use this when you have data in your application's format and need to convert it for the integration.

    <Frame>
      <img alt="mapApplicationObjects function step" src="https://mintcdn.com/paragon/3mNof4p8xpGmlkD6/assets/function-mapApplicationObjects.png?fit=max&auto=format&n=3mNof4p8xpGmlkD6&q=85&s=e7335a5796139b28669f7ef6ce51f1cc" width="400" data-path="assets/function-mapApplicationObjects.png" />
    </Frame>

    **Parameters:**

    * `mapping` — The field mapping configuration object passed as a parameter from Connect Portal User Settings.
    * `appObjects` — An array of application objects to transform.

    **Returns:** An array of integration objects with fields renamed according to the mapping.

    ```js theme={null}
    function yourFunction(parameters, libraries) {
      const { paragonUtils } = libraries;
      const { fieldMapping, applicationObjects } = parameters;

      const integrationObjects = paragonUtils.mapApplicationObjects(
        fieldMapping,
        applicationObjects
      );

      return { integrationObjects };
    }
    ```

    For example, if your field mapping maps `title` (application field) to `Subject` (integration field), an input of `[{ "title": "Buy groceries" }]` would produce `[{ "Subject": "Buy groceries" }]`.
  </Tab>
</Tabs>

Both functions support **Static** and **Dynamic** field mapping types. If the mapping or objects array is `null`, `undefined`, or not an array, the functions return an empty array.

## Considerations

When using Functions, there are a few things to keep in mind:

### Memory Constraints

At the system level, the container that processes workloads is limited by its available resources. Paragon limits step input and output sizes based on your billing plan:

* **Trial**: 50 MB
* **Basic**: 50 MB
* **Pro**: 100 MB
* **Enterprise**: 1 GB

### Time Constraints

Paragon sets time limits for how long Functions can execute based on your billing plan to ensure your workflows run smoothly. If a Function takes longer than allowed, the workflow step will fail.

Here are the maximum execution times by billing plan:

* **Trial**: 1 minute
* **Basic**: 1 minute
* **Pro**: 1 minute
* **Enterprise**: 1 hour
