# Invoke functions

## Overview

This guide dives into the methods of invoking functions in Rippling. You can invoke a function through:

-   Custom object actions
-   Custom app components
-   Automations
-   Pipelines

## Custom object actions in record or detail view

Custom object actions render as customer-defined buttons in key places throughout the Custom App UI. Functions and actions work in tandem to allow more power and flexibility in your custom app.

![Actions Button](https://developer.rippling.com/assets/images/ActionsButton-5c2292e4f6818e8c663ca53956d849d5.png)

We must define an action to run our function with the following steps:

1.  Select **Data > Catalog**.
    
2.  Select a _custom object_.
    
3.  Select the **Actions** tab. ![Actions Tab](https://developer.rippling.com/assets/images/ActionsTab-90f8700e1ac8c9a744c6b9009479e20c.png)
    
4.  Add a new action. The **Rippling Function** dropdown will show all the functions on which you have **View** access or greater.
    

Visibility Preference determines where the function can be called.

-   **List View** - The function can be called from a list and receives a list of record Ids.
-   **Detail View** - The function can be called from a single record and receives one record Id.
-   **Both** - The function can be called from either.

![Add Action](https://developer.rippling.com/assets/images/AddAction-21acbef030edefc3da6671e466dd9da7.png) 5. Click **Save**.

Your action will now appear under the Actions drop-down button on tables and record detail pages for custom objects.

## Custom app components

Some of the components in custom apps have click events that can be leveraged to make function calls. See [Page components](https://developer.rippling.com/documentation/rippling-platform/custom-apps/get-started#page-components) for more information. You must first create an action, then call that action from your component's click event.

### Create an action

1.  Select **Actions** from within your _custom app_.
2.  Add a new **Rippling Function** action.
3.  Toggle the **Trigger on Load** if you want to trigger your function as soon as the page loads instead of waiting for a click event.
4.  Select the **Function** you want to call.
5.  If you want to provide a **Payload** to your function, input the key value pairs you would like to pass in.

You can also dynamically reference component states and global variables via JavaScript expressions by clicking **ƒx**. For example, if you want to disable an option based on the input of the previous component, you can input a JavaScript expression to read from the previous component.

6.  Add an **Event handler**, which will execute in response to a specific event.

There are two types of **Events** available:

-   **On Trigger** - Executes when the function is triggered.
-   **On Response** - Executes when the function response is returned.

Select a **Handler**, which determines how the UI responds to your event.

-   **Control component** - Controls another component on the canvas, like refreshing a table or report.
-   **Control action** - Triggers another action on the page, which allows you to call multiple functions sequentially.
-   **Notification** - Displays a custom notification on the page.

You can add multiple **Event handlers**, creating a complete UI experience. For example, you could refresh a table and display a success message when your function response is returned.

7.  Your action will automatically be saved when you navigate away from the Actions UI.

### Link an action to a UI component

When adding a UI component, you will see an option to add an **Event handler**. This functionality is identical to adding an event handler on an action, as discussed in the section above.

To link the UI component to the action you previously created, select **Control action** from the **Handler** dropdown and select your action.

When saved, clicking the UI component will perform the action that calls your function.

## Automations

You can now use automations to trigger your functions, allowing you to automate function calls and call multiple functions sequentially.

1.  Select **Tools > Automation Studio**.
    
2.  Select the _automations_ you want to call the function from and open for editing or create a new automation and trigger.
    
3.  Drag the **Run Function** step from the Rippling Actions menu.
    
4.  Select the **Function** you want the automation to run.
    
5.  Enter the **Parameters** you want to pass to the function. For example, if you want to update a custom object record, you need to pass in the _Record ID_, and if you want to update an employee, you need to pass in the _Employee ID_.
    
    -   **Basic** - Type in values manually, or select from existing _automation variables_ in the UI.
    -   **Advanced** - Write a JSON object using the code editor. You can select from existing _automation variables_ here as well. The code editor has built-in code completion and will let you know if your input is in a valid format.
6.  _Optional_: Define an **[Output Schema](https://developer.rippling.com/documentation/rippling-platform/developer/functions/invoking-functions#output-schema)** to use the results from the API response in a later step of the automation.
    
7.  **Save** the automation. The function call will now be included as a step when the automation is triggered.
    

### Output schema

You can use the code editor to write a JSON object, or click **Generate schema for API response**, which will run a test call of your function and return the output schema.

#### Format

```text
{
    "type": "object",
        "properties": {
            "field_example_1" : {
                "type": "string",
                "format": "date"
            },
            "field_example_2" : {
                "type": "number"
            }
        }
}

```

#### Example

```text
{
    "type": "object",
    "properties": {
        "available_seats__c": {
            "type": "number"
        }
    }
}
```

You can also **insert automation variables** to set your automation variables using a function response. To do this, follow the steps below.

1.  Return the values from your function in the **function response body**.

![Function output variables](https://developer.rippling.com/assets/images/FunctionOutputVariables-c45119b29833d45107f6970caf0e321f.png)

2.  Write a JSON object in the output schema matching a property to each of the variables returned by your function.

![Automation output schema](https://developer.rippling.com/assets/images/WorkflowOutputSchema-e081619be33fa7b0667b7934358ebac8.png)

3.  **Save** the automation

Now, when the automation is executed, the function variables will be set when the **Run Function** step is executed, making the variables available in future automation steps. You can see them in the automation's **execution history** by looking at the **output** under the _execution details_.

![Automation output](https://developer.rippling.com/assets/images/WorkflowOutput-1a21a3e15bf47bfef96beea53c61635b.png)

You can also see the structure of your output schema under the **inputs** tab.

![Automation inputs](https://developer.rippling.com/assets/images/WorkflowInputs-588afdda70ef6802fcbe6ecee7db7388.png)

4.  Use the function variables by selecting an automation step and clicking **insert automation variables**. Here, you can select the variables from your function.

![Function output variables](https://developer.rippling.com/assets/images/WorkflowFunctionOutputVariables-d5c8f30455444aba8ceed52df5c49bd1.png)

## Pipelines

You can use functions to power custom pipelines, allowing you to ingest data from third-party APIs that require custom processing logic. Function-based streams are ideal when you need to handle complex API response structures, reformat values, or perform calculations before storing the data in Rippling.

> **Note:** To create a function-based stream, you must have access to the **Developer** app.

### Add a function-based stream

1.  From the main sidebar, select **Data > Pipelines**.
2.  Create a new custom pipeline or open an existing one for editing.
3.  In the _Data Streams_ panel, click **New**.
4.  For **Type**, select **Rippling Function**.
5.  Select an existing Rippling function, or create a new one. The function is responsible for calling the external API and returning the data in the expected format.
6.  Configure the record details, including:
    -   **Record ID path**: The field that uniquely identifies each record (used for deduplication).
    -   **Version path**: Path to the record version field that tracks when each record was last changed.
    -   **Field mappings**: Map the fields returned by your function to custom object fields.
7.  Publish the pipeline to start syncing data on a recurring schedule.

For more information about setting up custom pipelines, see the [custom pipeline setup guide](https://developer.rippling.com/documentation/rippling-platform/pipelines/custom-pipeline-setup).

## Resources

-   [Rippling API Docs](https://developer.rippling.com/documentation/rest-api)
-   [Rippling JavaScript SDK Docs](https://developer.rippling.com/documentation/js-sdk)
-   [Postman](https://www.postman.com/)
-   [Code Academy Javascript Tutorial](https://www.codecademy.com/learn/introduction-to-javascript)

Source: https://developer.rippling.com/documentation/rippling-platform/developer/functions/invoking-functions

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
