Grab Clappia’s 50% OFF Black Friday Deal before it’s gone! Ends 05 Dec 2025.
View offer →
#bf-banner-text { text-transform: none !important; }
Table of Content
Still need help?
Request support
Request Support
Help
 / 
 / 
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.

code workflow

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.

code workflow

Step Name

This is the name that appears in the workflow panel on the left side. If there are multiple Code Workflow Nodes in the workflow, set different step names like Get Address or Calculate Discount so you can identify them easily. This is only a display name and does not affect the code, variables, or logic.

Variable Name

When you save the Code Workflow Node, Clappia automatically generates a variable for this step (for example {code}). This variable represents the output of this node and is used internally when you reference its values in later workflow nodes.

When referencing the output in later nodes (like Email, If, or Create Submission), just type @ and start typing the step name (for example code or Get Address or whatever you have named it). Clappia will show the output labels you defined under Output Fields (read on below to know more), and you can select the one you need.

Code

The Code section is where you write custom JavaScript to perform calculations, validations, and other custom logic during the workflow execution. When you add the code workflow node, you will see a sample code appear. This sample code is only for reference on how the Code Workflow Node works and can be completely removed or replaced with your required code.

function main() { // Your code here output = {}; var num1 = Math.round(Math.random()*10); var num2 = Math.round(Math.random()*10); output['sum'] = num1 + num2; output['prod'] = num1 * num2; return output; }

What the sample code is about:

  • 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.

Tip: If you’re unsure about writing the code, you can use AI tools like ChatGPT, Claude, or Gemini to generate it for you. You can copy the sample code shown in the Code Workflow Node and paste it into the AI to help it understand the required structure. Then ask it to generate your required code in the same format.

Output Fields

code workflow

The Output Fields section is where you define which values returned by your code will be available as variables for use in other workflow nodes. These names must match the output names that are defined and returned inside your code.

Using the sample code above as an example, the code returns two outputs: sum and prod. To make these available outside the Code Workflow Node, you need to manually add them here.

In the Output Field text box, type:

  • sum  (this represents the sum of the two random numbers)

Then click on Add another field and type:

  • prod  (this represents the product of the two random numbers)

Once added, both sum and prod will be available as variables that you can use in other workflow nodes such as the Email Node, If Node, Create Submission Node, etc. Only the values that are returned by the code can be added in the output fields.

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 dynamically fill the email subject, body, or other fields. For example, the sum value can be shown inside an email to display a calculated result.
  • 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/Edit 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 @ 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 you need to pull up the output dynamically. For example, in the sample usecase, it will look like: {code#sum} and {code#prod}.

Example:

Let’s say you have an order management app or a simple feedback form where a user submits a form, and based on a randomly generated result, some users are selected for a special offer while others are not.

code workflow

Every time a submission is made, it triggers the workflow (if kept under ‘New submission flow’).

code workflow

As part of this workflow, the Code Workflow Node runs the same sample code shown again below;

In this sample code, it generates two random numbers, num1 and num2. Each of these is a whole number between 0 and 10. From these, the code calculates:

  • sum which is always between 0 and 20
  • prod which is always between 0 and 100

Now, imagine a simple example where a user is selected for a special offer only if they get the number 21. Which means you will have to use “prod” in the output field. If prod is 21, the user receives an email saying they have been selected for a special offer. If prod is anything else, the workflow simply continues without sending that email.

To set this up, add a Code node, IF node then an Email node.

In the Code Workflow Node, keep the same sample code.

code workflow


In the Output Fields section for this node, add prod so that the product value from the code is available to the next steps in the workflow.

In the If Node, set a condition to check whether the output prod is equal to 21. Type @ to get the code output fields variable.

code workflow
code workflow

So the condition should be {code#prod} = 21 .

The Email node below it will be sent to the user only if the condition is true, if not then nothing happens.

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.

Note on Workflows and Bulk Operations

Workflows in Clappia run on individual submissions, such as when a user submits or manually edits a record. However, when using Bulk Upload or Bulk Edit from the Submissions tab, workflows are not triggered, even though new submissions may be added or existing ones updated.

This is because workflows are designed to process one submission at a time. Triggering them for bulk operations can lead to incomplete or inconsistent results, especially for complex workflows.

If you need workflows to run after a bulk operation, currently you will need to open each submission manually and save it. This will count as an edit and trigger the workflow normally.

FAQs
What happens if my code requires data from an API but the API call fails?
If an API call fails within the Code Workflow Node, it may result in no data being returned. To handle this, consider adding error handling in your code, like setting a default output to indicate such failures.
How do I know if my JavaScript code has syntax errors before using it in a live workflow?
Test your JavaScript code in an online editor. This helps catch syntax errors before implementing it in Clappia. While entering code in Clappia, if there is any syntax error, it will prompt you immediately as well.
How do I safely store sensitive information, like API keys, within the Code Workflow Node?
To safely store sensitive information like API keys in the Code Workflow Node, avoid adding the key directly in the code if possible. The Code Workflow Node, however, keeps your data secure since users can’t view or inspect the code directly. If you're fetching data from an external site, consider using sites that don’t require an API key to further reduce exposure risk.
Is there a limit to how many output fields I can create in the Code Workflow Node?
Currently, you can add multiple output fields, but creating too many may complicate the workflow. It’s best to use only essential fields that other nodes will use to keep workflows efficient.
Are other programming languages supported in the Code Workflow Node?

Currently, only JavaScript is supported in the Code Workflow Node. Other languages are not yet supported, so all custom logic, calculations, and API interactions need to be implemented using JavaScript.

If you are unfamiliar with Javascript, you can always use AI assistance to generate the code for you.

Can I track the history of changes made to the code within the Code Workflow Node?
Clappia does not maintain a history for code within nodes. You can use version settings within Clappia to create multiple versions of your app to test out the code workflow node. However once it is saved, you will not be able to get back any previously used code in that node.
Try our free plan
It will answer many more questions within just 15 minutes.