Custom Code

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

Click the </> Edit Code button to add your custom code.


The sections below provide additional information regarding the Custom Code tool.

Reference data from previous workflow steps

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

For example, a Shopify Order Created trigger is the previous step before the Custom Code 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 before 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 step

While in the Builder tab, you can open the step and select Settings to use data from the Shopify Order Created trigger. This will display the step's Key. Click on the clipboard icon to Copy the step's Key.

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

context.steps['shopify'];

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.

We assigned the variable newVariable to payload and send payload to the next step.

After saving your changes, go back to the Builder tab view and locate the Custom Code step. Open Settings and click the clipboard icon to Copy the step's Key.

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

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

Log information

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

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 Mesa.log.info.

Last updated