The JavaScript Rules Engine allows you to model your business rules in Natural Language and Decision Table and deploy them to your JavaScript platform. This allows you to run your JavaScript version of your business rules in-proc. For example, inside the clients browser, NodeJS, … and even in offline mode.
In a couple of earlier posts we discussed how to use the REST API Client for JavaScript to execute your business logic (e.g., business rules, flow…) and return the results back to your JavaScript application. Also, we discussed how to build jQuery Validator for your forms using Business Rules. Now we want to take it one-step further in FlexRule v7.
Let's start with an example. In an AngularJS application for users registration you collect information like Country, State Name, Family and Email Address. We want to model rules to enforce the behaviours below on the client side, with no server round-trip:
1. Filters States based on the Country
2. Validates the form on Submit
Let's have a look at the application:
Filter
In this scenario, we used Decision Table to model the filtering behaviour:
Obviously, your rules can be as complex as you need them to be. You can have as many conditions (inputs) and actions (outputs) as you need.
Validation
In this scenario, we used Natural Language to model the validation behaviour:
Now your rules are all ready, let's deploy them to your AngularJS web application.
Deployment
Deployment can be achieved using the publish button. Select the target platform:
And then add all the logic you want to deploy to the JS platform:
And press the Publish button. That's all, your JS files are ready and can be in your JavaScript application. The good news is you can use the API to build the JS files of your rules dynamically as well.
In Action
After integrating the JS files for your rules, now when you select the Country then the States field is updated:
Also, when you try to submit the form, if you leave fields empty or in an invalid state (e.g., invalid email address) you get the error messages from JS BRE notifications:
Conclusion
The JavaScript Rules Engine not only allows you to visually model the rules on the web in both Decision Table and Natural Language, but it also allows you to execute them right inside your JavaScript platform (i.e., inside browser, NodeJS…) with no server call back or round trip!
In this post, we just showed you the filtering and validation scenarios, but our JavaScript Rules engine is very powerful and allows you to use Monadic operators, functions and expressions you normally use, so you can model complex business rules without any restrictions. With this new release you can maintain one version of the business rules and run them on both the client and server side; “the single source of truth”.
Please go ahead and download the FlexRule from http://download.flexrule.com and have a look at the sample called JavaScript Application yourself!
To learn more please visit https://resource.flexrule.com/knowledge-base/js-test-bed/
Last updated September 22nd, 2020 at 11:27 am, Published May 15th, 2017 at 11:27 am
CEO and the founder of FlexRule – He is an expert in architecture, design, and implementation of operational decisions, business rules, and process automation. Created Decision-Centric Approach, a methodology that brings People, Data, Rules, and Processes together to automate operational business decisions.
This approach is recognized by Gartner as the missing link to provide business value to organizations.
Leave A Comment
You must be logged in to post a comment.