Custom Code

The Custom Code by MESA app allows you to add complex logic to a workflow that might otherwise be difficult with MESA's built-in steps. You can integrate third-party services that MESA does not yet integrate with, write Javascript code, or send data to third-party services.

You can click on {/} Edit Code to add your custom code.

The sections below provide additional information regarding the Custom Code by MESA app.

Reference data from previous workflow steps

While editing the custom code in the Custom Code by MESA app, the payload parameter will contain data from the previous step before the Custom Code by MESA app.

For example, a Shopify Order Created trigger is the previous step before the Custom Code by MESA step. The payload parameter will reference the data from the Shopify Order Created trigger.

By default, the data of any steps that are not immediately prior to the Custom Code step will not be passed down. For example, we have provided a few steps in this order.

  1. Shopify Order Created trigger

  2. Shopify Retrieve Customer step

  3. Custom Code by MESA step

While in the Builder tab, you can locate the three dotted icon next to the step in order to use data from the Shopify Order Created trigger. This will display the step's Key. Click on the Copy button next to Key.

While editing the custom code in the Custom Code by MESA step, you can use the context parameter. The context parameter contains a steps object that contains the full payload for the step ran in this automation so far, keyed by each step's key.


Click here for more information about the context parameter.

Assign data from your custom code to a MESA variable

While writing custom code, you may need to send custom data further down in the workflow. To do this, you can assign custom data to a MESA variable. Variables are representations of data. When a workflow runs, variables are replaced with real data.

This example loops over each line item from the data related to the previous Shopify step. Then, logs information related to each product into the workflow's Logs tab.

In the following screenshot, MESA assigns the variable newVariable to {{payload}} and then sends {{payload}} to the next step.

After your custom code is established, go back to the Builder tab view and locate the Custom Code step. Click on the three-dotted icon and click on Copy next to the step's Key.

In your workflow's later steps, locate the field that needs the custom variable. To type the variable, enter {{ and then paste the copied key. Next, add a period (.) and then manually type out the variable that is assigned to the custom data. Lastly, add }}

For instance, where we set newVariable to the payload in the Custom step, the variable will read {{custom.newVariable}}

Log information

Scripts are ran in a stock V8 environment. This means that console.log() is not available so as an alternative, you can use

This lets you log info into your workflow's Logs tab and view the logged information whenever your workflow runs.

Click here for more information about

Last updated