Code

In the Design editor, the Code action is used to add JavaScript code to an action chain. To do so, add the Code action from the Action pallet to the action chain and enter the code in the Properties pane.

In the Code editor, you can use this action to create a local function.

Let's say you want custom code that examines pairs of prices in an array, and if the next price is at least 10% higher than the current one, it saves that pair. Here's a sample action chain that uses the Assign Variable and Code actions to perform this task:
define([
  'vb/action/actionChain',
  'vb/action/actions',
  'vb/action/actionUtils',
], (
  ActionChain,
  Actions,
  ActionUtils
) => {
  'use strict';

  class test extends ActionChain {

    /**
     * @param {Object} context
     */
    async run(context) {
      const { $flow, $application, $constants, $variables } = context;

      let prices = [100, 105, 112, 130];
      let priceJumps = [];
      
      for (let i = 0; i < prices.length - 1; i++) {
        if (prices[i + 1] / prices[i] >= 1.1) {
          priceJumps.push([prices[i], prices[i + 1]]);
        }
      }
    }
  }

  return test;
});