Code Node
Execute custom JavaScript directly inside your BotLance workflow to perform calculations, transform data, create workflow variables, and implement advanced business logic. The Code Node allows you to build powerful automations without relying on external services or backend code.
Introduction
Every business has unique requirements, and no visual workflow builder can provide a built-in node for every possible scenario. While BotLance includes a wide range of workflow nodes, there are times when you need complete control over how your data is processed. That's exactly why the Code Node exists.
The Code Node allows you to execute custom JavaScript as part of your workflow. Instead of sending data to an external automation platform or building your own backend service, you can write your business logic directly inside BotLance. This makes it possible to perform calculations, manipulate data, evaluate conditions, generate new variables, and prepare information for the next step in your workflow without introducing unnecessary complexity.
Every script runs inside a secure, isolated environment and integrates seamlessly with the rest of your workflow. Once the script finishes executing, the workflow immediately continues to the next node using the values returned by your code.
Why We Built the Code Node
As automation becomes more advanced, there are always situations where built-in workflow nodes aren't enough. A business might need to calculate a custom commission, qualify a lead using its own scoring system, format data before sending it to an external API, or perform calculations that are unique to its industry. Traditionally, these tasks required leaving the automation platform altogether.
Many automation tools solve this by offering separate code modules or requiring developers to create custom APIs and backend services. This often means sending data outside the workflow, waiting for another service to process it, and then bringing the result back before the workflow can continue. While this approach works, it introduces additional complexity, increases maintenance, and creates more points of failure.
The Code Node eliminates this dependency by allowing your JavaScript to execute directly inside the workflow. Instead of relying on external services for simple business logic, everything happens within BotLance itself. Your workflow remains clean, your execution is faster, and your automation becomes easier to manage because all of your logic lives in one place.
Whether you're replacing a small Make.com Code Module, an n8n Code Node, a serverless function, or a lightweight backend API, the Code Node provides a much simpler way to solve the same problem without leaving your workflow.
What Can You Build?
The Code Node is designed to handle almost any business logic that can be written in JavaScript. It isn't limited to a single industry or use case, making it one of the most flexible nodes available in BotLance.
For sales and CRM workflows, you can build lead scoring systems, qualify customers based on custom rules, calculate commissions, or determine whether a prospect is eligible for an appointment. In e-commerce workflows, you can calculate discounts, determine shipping costs, apply taxes, generate loyalty points, or create dynamic pricing based on customer information.
If you're working with AI, the Code Node can preprocess user data before it's sent to an AI model or clean and restructure AI responses before they're passed to the next workflow node. It can also generate new workflow variables, apply complex business rules, and intelligently route customers through different automation paths based on your own criteria.
The Code Node is equally useful for processing data. You can parse JSON responses, format dates and times, convert currencies, analyze survey responses, score quizzes, clean imported data, or transform information into the exact format required by another integration.
In short, if your business logic can be written in JavaScript, there's a good chance it can be executed directly inside the Code Node, allowing your entire automation to remain within BotLance instead of depending on external services.
How the Code Node Works
Although the Code Node is extremely powerful, the way it works is intentionally simple. Every time a workflow reaches a Code Node, BotLance passes the available workflow data into your script, executes your JavaScript inside a secure sandbox, captures the values returned by your code, updates the workflow variables, and immediately continues to the next node.
The execution process follows a straightforward sequence:
Workflow
↓
Workflow Variables
↓
Code Node
↓
JavaScript Execution
↓
Return Object
↓
Workflow Variables Updated
↓
Next Workflow NodeUnderstanding Workflow Variables
Every workflow in BotLance works by passing information from one node to the next. This information is stored as workflow variables, which act as the shared data source for your entire automation. As users interact with your workflow, AI generates responses, APIs return data, or integrations complete an action, new variables are automatically created and made available to subsequent nodes.
For example, imagine a visitor fills out a lead form. Their name, country, budget, and age can all become workflow variables.
name = John
country = Pakistan
budget = 1500
age = 25These values don't have to be created manually inside the Code Node. They're usually generated by previous nodes such as Data Collection, AI, API Response, Integrations, or even another Code Node. By the time your workflow reaches the Code Node, all of this information is already available for you to use.
The Code Node doesn't own or store these variables. Its job is simply to read them, perform whatever business logic you've written, and optionally return new values that become part of the workflow.
Accessing Workflow Variables
The Code Node provides two different ways to access workflow data. Depending on the complexity of your workflow and your personal preference, you can either expose every available variable automatically or manually choose only the variables you need.
For most workflows, the automatic approach is the quickest and most convenient option. However, if you're building larger automations or prefer cleaner code, manual mapping gives you greater control over the data that's available inside your script.
Automatic Context (Recommended)
Automatic Context is the default and recommended option for most workflows. When enabled, BotLance automatically makes every workflow variable available inside your JavaScript, so you can immediately start writing your business logic without performing any additional configuration.
Variables can be accessed through the workflow context.
ctx.variables.name
ctx.variables.country
ctx.variables.age
ctx.variables.budgetBecause every workflow variable is already available, this mode is perfect when you're rapidly building new automations or testing ideas. You don't need to think about mapping individual fields before writing your code, which makes development much faster.
Automatic Context is especially useful for beginners because it removes unnecessary setup and lets you focus entirely on your business logic. It's also an excellent choice for AI-powered workflows where the available variables may change as your automation grows.
In most situations, this will be the only mode you'll ever need.
Manual Mapping
While Automatic Context is convenient, there are situations where exposing every workflow variable isn't necessary. In larger workflows, you may only need two or three values, and manually selecting those variables can make your code much cleaner and easier to understand.
Manual Mapping allows you to choose exactly which workflow variables should be available inside your script. Instead of referencing long variable paths, you can assign simple aliases that make your JavaScript easier to read.
For example, imagine your workflow contains a variable called:
customer_budgetInstead of writing:
ctx.variables.customer_budgetbudgetbudgetThis approach keeps your code shorter, reduces visual clutter, and makes larger scripts much easier to maintain. It also avoids exposing unnecessary workflow data to your script, which can improve performance and make debugging simpler.
Although Manual Mapping requires a little more setup, many developers prefer it when building larger or more complex workflows because it results in cleaner, more readable code.
Test Variables
Writing code without testing it can quickly become frustrating, especially when a workflow contains multiple nodes. To make development easier, the Code Node includes Test Variables, allowing you to simulate workflow data without running the entire automation.
Test Variables exist only while you're working inside the editor. They let you define sample values that behave exactly like real workflow variables whenever you click Run.
For example, you might test your script using the following data:
country = Pakistan
budget = 2000
age = 30When you execute the script, BotLance temporarily uses these values instead of waiting for a real user to trigger the workflow. This makes it much easier to experiment with calculations, verify business rules, and identify mistakes before publishing your changes.
It's important to understand that Test Variables are used only during development. Once your workflow is published, they are completely ignored, and the Code Node automatically receives the actual data generated by your workflow.
This allows you to develop and test with confidence while ensuring that production workflows always operate using real customer information.
Secure Sandbox
Security is an important part of any platform that allows users to execute custom code. For this reason, every Code Node runs inside its own isolated JavaScript sandbox, ensuring that your scripts remain completely separated from the underlying BotLance infrastructure.
The sandbox allows your JavaScript to safely process workflow data while preventing access to sensitive parts of the platform. Scripts cannot access server files, interact with another customer's data, execute dangerous system commands, or interfere with workflows belonging to other users.
This isolation means every workflow executes independently and securely. Even if a script contains an error, it remains confined to that workflow and cannot affect the stability of the rest of the platform.
By combining flexibility with isolation, the Code Node gives developers the freedom to implement custom business logic while maintaining the security and reliability expected from a multi-tenant SaaS platform.
Return Values
Once your JavaScript has finished executing, the final step is to return the result back to the workflow. Whatever your script returns automatically becomes available to the next node, allowing the rest of your automation to continue using the newly generated data.
The simplest way to do this is by returning an object.
return {
score: 90,
category: "Hot Lead"
};score = 90
category = Hot LeadFrom this point onward, every subsequent node in your workflow can access these variables. For example, you might use the score inside a Condition Node, include the category in an AI prompt, send it to your CRM through an API Request, or display it to the customer. Returning data is how the Code Node shares the results of its work with the rest of your automation.
One of the biggest advantages of this approach is that you don't need to manually create workflow variables elsewhere. Simply return the values you want, and BotLance automatically makes them available throughout the workflow.
Reserved Return Keys
In addition to returning standard variables, the Code Node also supports several reserved return keys that perform specific workflow actions. These keys allow your script to do more than calculate values—they can directly update workflow data and manage tags without requiring additional nodes.
setVariables
The setVariables key explicitly updates one or more workflow variables. This is useful when you want to overwrite existing values or create multiple variables in a structured way.
return {
setVariables: {
score: 95,
level: "Gold"
}
};addTags
return {
addTags: [
"VIP",
"Qualified"
]
};removeTags
Removing tags works in exactly the same way. If your business logic determines that a contact no longer belongs to a particular segment, you can remove the tag directly from the Code Node.
return {
removeTags: [
"Cold Lead"
]
};Execution Flow
Although the Code Node can perform extremely sophisticated calculations, its execution process remains simple and predictable. Every time the workflow reaches a Code Node, BotLance follows the same sequence from beginning to end.
Collect User Data
↓
Workflow Variables Created
↓
Code Node Executes
↓
Business Logic Runs
↓
Return Object
↓
Workflow Variables Updated
↓
Workflow ContinuesThis entire process happens automatically and usually completes within a fraction of a second. Unlike external automation platforms, there is no need to send data to another service, wait for an API response, or reconnect the results back into your workflow. Everything happens inside BotLance, making execution faster, more reliable, and much easier to maintain.
Why Use the Code Node?
As your workflows become more advanced, you'll eventually encounter situations where visual workflow nodes alone aren't enough. Every business has unique rules, calculations, and decision-making processes that cannot always be represented through drag-and-drop automation.
The Code Node fills this gap by allowing you to implement custom business logic without leaving BotLance.
Instead of creating a Make.com Code Module, building an n8n workflow, deploying a serverless function, or maintaining a small backend API, you can keep all of your logic inside the same workflow where it naturally belongs.
This not only simplifies development but also makes workflows easier to understand. Anyone reviewing your automation can see both the workflow and the business logic together in a single place instead of tracing requests across multiple external services.
For many organizations, this significantly reduces complexity while improving the long-term maintainability of their automations.
Performance Benefits
Executing JavaScript directly inside your workflow offers several advantages beyond convenience. Because your business logic runs within BotLance, there is no need to perform additional network requests or depend on external automation platforms for simple calculations.
Keeping everything inside a single workflow results in lower latency, faster execution, and fewer external dependencies. It also reduces maintenance because there are fewer services to monitor, fewer APIs to manage, and fewer opportunities for failures caused by third-party outages.
As workflows grow over time, this approach makes them easier to maintain and significantly lowers the operational cost of running complex automations. In many cases, a single Code Node can replace several external services while producing a workflow that is both faster and easier to understand.
Best Practices
Although the Code Node gives you complete flexibility, writing clean and focused scripts will make your workflows easier to maintain over time.
Try to keep each Code Node responsible for a single task instead of combining unrelated business logic into one large script. Returning only the variables you actually need keeps workflows cleaner and reduces unnecessary data. Using clear and meaningful variable names also makes your automations much easier to understand, especially when revisiting them months later.
For most workflows, Automatic Context provides the best development experience and should be your default choice. Manual Mapping becomes more valuable as workflows grow in complexity and you want tighter control over the variables available inside your script.
Before publishing any workflow, take advantage of Test Variables to verify that your code behaves as expected. Testing with realistic data helps identify problems early and gives you confidence that your workflow will perform correctly once it's live.
Finally, if your business logic becomes particularly large or complex, consider dividing it across multiple Code Nodes. Smaller, focused scripts are easier to debug, easier to reuse, and much simpler to maintain than one large block of code.
Common Use Cases
Because the Code Node is completely flexible, it can be applied across almost every type of business workflow. Sales teams use it to score leads, qualify prospects, and calculate commissions before routing opportunities to the appropriate sales representative. Marketing teams rely on it to segment audiences, personalize campaigns, and generate dynamic customer data before triggering follow-up automations.
Customer support teams often use the Code Node to evaluate incoming requests, prioritize conversations, and prepare data before sending it to AI assistants. E-commerce businesses can calculate discounts, taxes, shipping costs, loyalty rewards, or promotional pricing without requiring external services.
The same flexibility makes it valuable for industries such as healthcare, education, finance, real estate, human resources, and SaaS onboarding. Whenever your workflow needs calculations, data transformation, or custom business rules, the Code Node provides a simple and reliable solution.
Future Possibilities
The Code Node has been designed with future expansion in mind. While it already provides a powerful environment for executing JavaScript, it also serves as the foundation for more advanced development features that may be introduced over time.
Future improvements may include intelligent code autocomplete, built-in helper functions, advanced debugging tools, a workflow variable explorer, reusable code templates, a shared snippet library, and reusable function collections that can be shared across multiple workflows. Support for additional programming languages, such as TypeScript or Python, may also become available in future releases.
As BotLance continues to evolve, the Code Node will grow alongside it, giving developers even more flexibility while keeping the workflow experience simple and intuitive.
Final Summary
The Code Node transforms BotLance workflows from simple automation sequences into fully programmable business processes. Instead of relying on external automation platforms or backend services for custom logic, you can write secure JavaScript directly inside your workflow, access existing workflow variables, perform complex calculations, generate new data, manage tags, and continue the automation without interruption.
Whether you're building a simple lead scoring system or implementing sophisticated business rules for enterprise workflows, the Code Node provides the flexibility to solve problems that would otherwise require external infrastructure. By keeping your logic inside BotLance, your workflows become faster, easier to maintain, and significantly more powerful, allowing you to build advanced automations from a single, integrated platform.