Skip to main content

Rules Engine Execution

The Business Rule task allows the evaluation of business rules defined in spreadsheets. Supported formats include CSV, XLS, and XLSX.

Definitions

  {
"name": "execute_rule",
"taskReferenceName": "execute_rule_ref",
"inputParameters": {
"ruleFileLocation": "https://business-rules.s3.amazonaws.com/rules.xlsx",
"executionStrategy": "FIRE_FIRST",
"inputColumns": {
"InputDate": "${workflow.input.inputDate}",
"ProductType": "${workflow.input.productType}"
},
"outputColumns": [
"Discount"
]
},
"type": "BUSINESS_RULE"
}

Input Parameters

AttributeDescription
ruleFileLocationURL of the rule file to be evaluated. For example, files can be stored on the web, AWS S3, Azure Blob, etc.
Example:
executionStrategyStrategy for rule execution. Supported options are:
  • FIRE_FIRST - Uses the first rule that matches to generate the output.
  • FIRE_ALL - Uses all matching rules to generate the output, with subsequent rules overwriting previous values.
inputColumnsSpecifies the inputs to the rule file. Values can be derived from previous task/workflow input or static input.
outputColumnsList of columns that will be present in the task output. Columns not listed here are considered input columns whose values must be specified.
cacheConfigEnabling this option allows saving the cache output of the task. On enabling, you can provide the following parameters:
  • ttlInSecond - Provide the time to live in seconds. You can also pass this parameter as a variable.
  • key - Provide the cache key, which is a string with parameter substitution based on the task input. You can also pass this parameter as a variable.
optionalEnabling this option renders the task optional. The workflow continues unaffected by the task's outcome, whether it fails or remains incomplete.

Execution Strategy

To get an understanding of the executionStrategy (referred to as Method in UI), consider the below table:

NamePrice
Phone10$
Phone11$

Let’s assume the input name is Phone. If the executionStrategy is FIRE_FIRST, then the output price will be $10. On the other hand, if the executionStrategy is FIRE_ALL, then the output price will be $11, as the second rule will overwrite the value of the price.

Supported Operators

Business rule task supports the following operators:

  1. Comparison Operators: <=, >=, =, <, >.
  2. String Operators: Equals (=) and Not Equals (!=).
  3. List Operators: inList and !=inList. For example, productName inList({"phone","laptop"}) will match if productName is phone or laptop.
  4. Operator: createList. For example, createList({"A","B","C"}) will generate list {"A", "B", "C"} in output.
  5. Date Comparison: Supported formats are yyyy-MM-dd, yyyy-MMM-dd and yyyy-MM-dd HH:mm:ss.

Examples



  1. Add task type Business Rule.
  2. Configure the task with an input file and parameters.

Adding Business Rule

Sample Workflow

Consider the following rule file:


productType | productCategory | purchaseDate | itemCount | price | Discount | ShippingCharges
electronics | cellphone | <=2022-04-22 | 8 | != 100 | 11% | 5$
electronics | cellphone | <=2022-04-22 | 8 | < 100 | 13% | 15$
electronics | laptop | > 2022-mar-12 | >10 | <10.2 | 5% | 4$
beauty | powder | = 2022-01-01 | >15 | >=10.3 | 15% | 2$
food | pizza | < 2022-03-22 12:20:22 | 25 | >300 | 7% | 10$

The workflow definition is as follows:


{
"name": "TestRule",
"tasks": [
{
"name": "rule",
"taskReferenceName": "rule",
"inputParameters": {
"ruleFileLocation": "Product.xlsx",
"executionStrategy": "FIRE_FIRST",
"ruleFileStorage": "LOCAL",
"inputColumns": {
"productType": "${workflow.input.productType}",
"productCategory": "${workflow.input.productCategory}",
"price": "${workflow.input.price}",
"itemCount": "${workflow.input.itemCount}",
"itemCode": "${workflow.input.itemCode}"
},
"outputColumns": [
"Discount",
"ShippingCharges"
]
},
"type": "BUSINESS_RULE"
}
]
}

If the workflow is triggered using the following input:


{
"productType": "electronics",
"productCategory": "cellphone",
"price": "5",
"itemCount": "8",
"purchaseDate": "2022-04-22"
}

It will match the first row and generate output as:


{
"Discount" : "11%",
"ShippingCharges" : "5$"
}

Let’s see another case where the same workflow is triggered using the following input:


{
"productType": "electronics",
"productCategory": "laptop",
"price": "10.0",
"itemCount": "12",
"purchaseDate": "2022-04-22"
}

In order to compare double values, we should put the suffix .0. If it is not there, then it will match the third row and generate output as:

    {
"Discount" : "5%",
"ShippingCharges" : "4$"
}

When we use FIRE_ALL as executionStrategy, with the workflow input as:

   {
"productType": "electronics",
"productCategory": "cellphone",
"price": "5",
"itemCount": "8",
"purchaseDate": "2022-04-22"
}

It matches the second row since it also matches the criteria and generates output as:

    {
"Discount" : "13%",
"ShippingCharges" : "5$"
}