beginnerEasy Start
Custom Code
This template describes the Custom Code Rule Flow, a functional example designed to demonstrate how custom scripting can be integrated into a decision workflow within the DecisionRules environment.
David Škarka
Template author
The primary objective of this Rule Flow is to demonstrate the usage of the Custom Code node. It serves as a practical template for executing custom JavaScript logic within a flow to perform calculations that may exceed the scope of standard nodes.
Specifically, this flow takes two numerical inputs and calculates their product.
Solution Components
The workflow sequences the logic through the following stages:
Use This Template To Learn How To:
- Start Node: The entry point that receives the input data.
- Custom Code Node (code): This is the core engine of the flow. It executes a JavaScript snippet to process the data:
- Calculation: It reads value1 and value2 from the workflow input and multiplies them.
- Output Assignment: It assigns the result to workflow.output.product.
- Logging: It logs the multiplication result to the console for debugging purposes.
- End Node: Finalizes the execution and returns the calculated product to the requester.
Use This Template To Learn How To:
- Implement Custom JavaScript: How to use the Custom Code node to write and execute scripts directly within a workflow.
- Access Workflow Data: How to programmatically reference workflow.input and set workflow.output within a script.
- How to propagate a script result to the flow
More Templates
See Other Templates
financial servicessuggested
A/B Testing
Discover a simple way to assign a test group for performing A/B Testing on your decisions.
financial servicessuggested
Risk Based Pricing
Discover a simple way to apply a suitable Risk Based Pricing matrix based on a type of client.
financial servicessuggested
Eligibility and Policy Rules
Discover a simple way to define and execute various sets of rules and get the final decision outcome.