When you are creating business rules, you sometimes need to perform operations that are not built natively into the Progress Corticon decision automation platform. For example, you may need a complex mathematical formula. Custom operators provide a mechanism to extend the Corticon platform with your own functions. These custom operators greatly simplify rule-modeling activities as modelers do not need to build complex formulas, which makes the development and maintenance of business rules easier.
Extensibility through custom operators is a key benefit of the Corticon platform. In this blog post, we explore how to create robust, flexible Corticon.js custom operators that go beyond standard type and parameter constraints.
We’ll use the Present Value and Future Value example operators from the samples in GitHub.
These operators calculate the values over time using parameters like interest rates and number of years (duration)—both of which can be represented in many ways. For example, the duration could be just 4 as in 4 years, or it could be 1.5 to represent one and a half years. It could also be a date like 2028-12-01, in which case the duration is the difference between the date and today’s date (assuming today is 2024-12-01, then the duration is 4 years).
Read on to learn how to support such flexible operators in your projects.
Custom operators allow you to:
A custom operator that can handle diverse input types can make life easier for the modeler using the operator.
Consider the following powerful design principles.
A single parameter can accept various data types. In our financial example, the number of years parameter can be:
Check the function checkForValidTypes in GitHub for an illustration of parameters validation with all the supported Corticon types.
Robust operators anticipate and handle various input scenarios:
For example, in the function presentValue, we default the duration to one year if no time period is specified:
... let numberOfYears = params[2];
if (numberOfYears === undefined || numberOfYears === null)
numberOfYears = 1;
Operators should gracefully handle different input representations. For example, a modeler could pass the number of years parameter as a String representing numbers. Fortunately, for the interest rate parameter in our case, we do not need to write conversion code. Corticon.js decimal implementation accepts both JavaScript numbers as well as strings as input parameters so there is no need to explicitly convert a string to a number in the first place.
Implement robust type validation:
When designing custom operators:
Our financial custom operator:
One of the most powerful aspects of custom operators is their seamless integration into the Corticon rule modeling environment. Here's how you'll typically use the financial custom operators:
// In your Corticon rule sheet Finance.presentValue = getDecimal('PresentValue', Finance.inputValue1, Finance.interestRate, Finance.years)
Finance.futureValue = getDecimal('FutureValue', Finance.inputValue2, Finance.interestRate, Finance.years)
The custom operators shine in their ability to handle diverse inputs. To compute the present value of 10,000 at 5.5% over 3 years: Finance.presentValue = getDecimal('PresentValue', 10000, 5.5, 3)
To compute the present value of 10,000 at 5.5% over 3.5 years where the duration is a String: Finance.presentValue = getDecimal('PresentValue', 10000, 5.5, '3.5')
To compute the present value of 10,000 at 6.5% over the duration represented by the difference between a date and today: Finance.presentValue = getDecimal('PresentValue', 10000, 6.5, someDate)
Custom Corticon operators bridge the gap between complex business logic and intuitive rule modeling. By creating flexible, intelligent operators, you empower business analysts to build more sophisticated decision services with less complexity.
To sign up for a trial or demo of the Corticon platform, visit our Getting Started page.
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites