Table of Content
Still need help?
Request support
Request Support
Help
 / 
Heading
 / 
Workflows
 / 

Workflows: Code Workflow Node

This article explains the Code Workflow Node, which allows you to integrate custom JavaScript into workflows. It provides advanced functionality to handle complex logic, calculations, data processing, and external API calls, expanding the automation capabilities of your workflows. Learn more about using workflows in Clappia here.

Used For

  • Performing complex calculations that go beyond standard workflow blocks.
  • Processing data dynamically, such as parsing and transforming inputs from other blocks.
  • Making API requests to fetch, process, or store external data within workflows (e.g., retrieving addresses from GPS coordinates).
  • Formatting data for precise business requirements, like custom date or currency formats.

Editing the Node

Click on the node and start editing on the panel that appears on the right side.

Step Name

This is the name that appears in the Workflow on the left side. If there are multiple Code Workflow Nodes in the workflow, set different step names like Get Address.

Variable Name

After saving, the Code Workflow Node generates a unique Variable Name (e.g., {code_1}), which holds the output generated by the code. This variable can be used in subsequent workflow nodes to reference the custom JavaScript output directly. Learn more about using variables in workflows here.

Code

The Code section is where you write custom JavaScript. Upon adding the code workflow node, a sample function appears as follows:

In this example:

  • num1 and num2 are randomly generated numbers.
  • sum and prod are the calculated sum and product of these numbers.
  • The output object stores these values, which can then be used in other workflow nodes.

This example code can be removed and a custom java script code according to your requirement can be added here.

Output Fields

The Output Field is where you define which outputs from the code will be available as variables for use in other blocks. Each key in the output object represents a variable. For example, in the above code, if you define the output field as sum, the app will recognize sum as a variable that can be used in other blocks.

You can add multiple output fields by clicking on ‘Add another field’ and entering their names one by one:

  • sum: The sum of the two random numbers.
  • prod: The product of the two random numbers.

These output variables can then be pulled into other nodes, such as the Email Node or Create Submission Node, for further actions.

Using the Code Workflow Node Outputs in Workflows

Once the output fields are defined, the values can be referenced in other nodes:

  • Email Node: Use the variables from the Code Workflow Node to populate the email body, subject, or other fields dynamically. For instance, the sum variable can be included to display calculated values within an email.
  • If Node: Set conditions based on the code’s output. For example, if the output score is above a certain threshold, trigger specific actions in the workflow.
  • Create Submission Node: Automatically populate fields with the Code Workflow Node’s outputs in a submission, allowing custom-calculated values or processed data to be stored.

To pull up any of the output variables from the Code workflow node, type in @ followed by the name of the node (if you haven’t changed the name, it will be code). You will see the output labels. Select the ones needed to pull up the output dynamically.

Note

  • Output Variables: Only fields defined in the output object will be available in other workflow nodes.
  • Testing: Test your code to ensure outputs are correct before using it live, especially when integrating external APIs.

The Code Workflow Node introduces advanced capabilities to Clappia workflows, enabling dynamic, JavaScript-powered automation that enhances data handling, custom logic, and integrations.

FAQs
Try our free plan
It will answer many more questions within just 15 minutes.