'Code' action

Use 'Code' action to pass data between actions through the execution context, execute actions with custom input, and much more.

Sergey Shurygin avatar
Written by Sergey Shurygin
Updated over a week ago

Use the Code action to insert a piece of Twig code directly into condition/actions blocks.

How to add a Code action

In an condition/action block press the Plus button and select Add code in the menu:

Then click Edit and enter your Twig code:

Example of a Code action

A Code action below is added to a Match record's match actions, and is executed for each of the found locations:

It counts the number of locations within the 25-mile distance from the base location by incrementing the locations_quantity variable in the execution context using the Set() function, and appends such a location to the list of locations stored in the locations variable. Both variables are then used in a Send email's email body Twig template to send a report to the Mapsly admin.

Typical use cases for a Code action

A Code action is especially useful for:

  • storing intermediate results of preceeding actions in the execution context (in a sequence of actions) so they can be used in further actions down the execution flow;

  • executing other actions with custom context using the Do() function, which is useful for executing nested actions from within another action, or to create related records;

  • executing a custom business logic and produce complex output that cannot be implemented using other actions.

Save Code's resulting value in Execution Context

You may also save the resulting value of the resolved Code Twig template in the Context by assigning a name, similarly to any other action:

Once a name is assigned, your Code actions will look like this:

and subsequent actions' Twig fields can retrieve these values using these names, like {{distance}} and {{verified}}.

Implementation is already included in your Mapsly subscription

Your Mapsly subscrption includes implementation services including writing code using the Mapsly automation suite. So if you'd like to implement custom processes using the Mapsly automation suite, simple contact us in chat or at [email protected] - and our engineers will configure everything for you within hours.

Did this answer your question?