BRF+ Function (Event Mode Scenario)
In this blog, Let’s try to create a BRF+ Function with Event mode.
A function is the rule interface in BRFplus and acts as a link between the application code and the BRFplus code.
A function carries a mode, context and a result. It imports the context from the calling application and passes the context data to the assigned top expression or ruleset for further processing. After processing, the function returns the calculated result to the calling application. To create function from scratch, follow the Creating a Function.
- Mode (Event mode)
A ruleset is a collection of rules to be processed in a particular business case. It serves as an entry point for rule processing and can be used as an alternative to a top expression assigned to a function.
The mode of operation setting of the assigned function must be either
Event Mode or
Functional and Event Mode.
Here, I have designed a scenario to calculate actual price of item using event mode (ruleset), following are the steps:
- Find the base price
- Apply State Tax
- Apply Central Tax
- Find the Festive season
- If transaction date falls in festive season, apply festival discount
A decision table expression is used to compare a given input against a list of predefined combinations of conditions. Each combination has an individual result assigned which is returned as the expression result when the input data matches the particular combination.
Here the combinations are,
Calculating the basic price using the expression,
Table settings are shown below:
Including 18% of state tax with the basic price using the below Formula expression,
Including 18% of Central tax with the base price (after inclusion of state tax),
Finding the month from current date using the below Formula expression (Using standard date function DT_PART_MONTHS)
Based on the month, check whether it is festival season based using Boolean expression:
As an example, I have taken December and January as festival months. i.e., Festival discount will be applicable for transactions performed in them:
Finally calculating the final price,
- If the current purchase date falls in festive months then 50% discount will be applied to the final price (after central tax).
- If the current purchase date is not falling in festive months then the result will give the final price (after central tax).