Workflow Action: Custom Code
Overview
The Custom Code action in Stack allows you to enhance your workflow by writing and executing custom JavaScript code. This feature enables you to incorporate properties from previous steps, perform operations, and use the output in subsequent steps, providing a flexible way to extend the functionality of your workflows.
Action Name
Custom Code
Action Description
The Custom Code action lets you execute JavaScript code within a workflow. This capability allows users to process data and generate output that can be utilized in the following steps of the workflow.
Action Details
How to Configure
-
Action Name: Assign a name to your custom code step that clearly reflects its purpose within the workflow.
-
Language: The default and currently only supported language is JavaScript.
-
Property to Include in Code: Define key-value pairs where the key will be referenced in your code. The value can be either hardcoded or dynamically mapped from previous workflow steps. Use these pairs in your code by referencing
inputData.<key>. For example, if the key isnumber1, access it asinputData.number1. -
Code: Write your JavaScript code to process the values from previous steps. Ensure that the output is structured as a JavaScript object or an array of objects. For instance, you might use
output = { result: sum }.
Field Descriptions
-
Action Name: The name displayed for the action in the workflow. (Mandatory)
-
Language: The programming language for the custom code, which is JavaScript by default. (Mandatory)
-
Property To Include In Code: Fields to be used within the code, mapped from previous steps. Access these with
inputData.keyName. (Mandatory) -
Code: The JavaScript code that performs the desired operation. The code should output a JavaScript object. (Mandatory)
Example
// This code is wrapped in an async function
const sum = inputData.number1 + inputData.number2;
// Return the result as a JavaScript object
output = { result: sum };
This example demonstrates adding two numbers from the mapped properties number1 and number2, then outputting their sum.