Build
Compiles rule definitions from JSON or GRL format into a binary Knowledge Base file (.grb) that can be efficiently executed by the Execute node.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
-
Rules - The rule definitions to compile. Can be either:
- JSON Object: A structured JSON object containing rule definitions (when Rules Format is set to JSON)
- GRL String: A string containing Grule Rule Language syntax (when Rules Format is set to GRL)
-
Rules Binary Path - The output path where the compiled binary Knowledge Base file (.grb) will be saved. The
.grbextension will be added automatically if not provided.
Options
- Rules Format - The format of the input rules:
- JSON: Rules provided as a JSON object
- GRL: Rules provided in Grule Rule Language (GRL) format
Examples
Example 1: Building Rules from GRL Format
This example compiles a simple GRL rule that evaluates customer discount eligibility:
// Define your GRL rules as a string
msg.grlRules = `
rule CheckDiscount "Determine customer discount" salience 10 {
when
customer.TotalPurchase >= 1000 && customer.IsMember == true
then
customer.Discount = 15;
customer.DiscountReason = "VIP Member Discount";
}
rule CheckStandardDiscount "Standard discount for purchases over 500" salience 5 {
when
customer.TotalPurchase >= 500 && customer.Discount == 0
then
customer.Discount = 10;
customer.DiscountReason = "Standard Discount";
}
`;
// Set the output path for the binary file
msg.rulesPath = "C:/RPA/rules/customer_discount.grb";
Configuration:
- Rules:
{{msg.grlRules}} - Rules Binary Path:
{{msg.rulesPath}} - Rules Format:
GRL
Example 2: Building Rules from JSON Format
This example compiles rules from a JSON object for product pricing logic:
// Define your rules in JSON format
msg.pricingRules = {
"name": "PricingRules",
"desc": "Product pricing and discount rules",
"salience": 10,
"when": "product.Category == 'Electronics' && product.Price > 500",
"then": [
"product.Discount = 20",
"product.FreeShipping = true"
]
};
// Set the output path
msg.rulesPath = "C:/RPA/rules/pricing_rules.grb";
Configuration:
- Rules:
{{msg.pricingRules}} - Rules Binary Path:
{{msg.rulesPath}} - Rules Format:
JSON
Example 3: Building Complex Business Rules
This example demonstrates building more complex business rules with multiple conditions:
msg.approvalRules = `
rule ManagerApprovalRequired "Check if manager approval is needed" {
when
request.Amount > 5000 && request.Department == "Finance"
then
request.RequiresManagerApproval = true;
request.ApprovalLevel = "Manager";
}
rule DirectorApprovalRequired "Check if director approval is needed" {
when
request.Amount > 10000
then
request.RequiresDirectorApproval = true;
request.ApprovalLevel = "Director";
}
rule AutoApprove "Auto-approve small requests" {
when
request.Amount <= 1000
then
request.AutoApproved = true;
request.ApprovalLevel = "Auto";
}
`;
msg.rulesPath = "C:/RPA/rules/approval_workflow.grb";
GRL Syntax Reference
Basic Structure
rule RuleName "Rule Description" salience 10 {
when
// Conditions
then
// Actions
}
Key Components
- rule: Keyword to define a new rule
- RuleName: Unique identifier for the rule
- "Description": Human-readable description
- salience: Priority of the rule (higher values execute first)
- when: Condition block (must evaluate to true for the rule to fire)
- then: Action block (executed when conditions are met)
Common Operators
- Comparison:
==,!=,>,<,>=,<= - Logical:
&&(AND),||(OR),!(NOT) - Arithmetic:
+,-,*,/,%
Tips
- Use Descriptive Rule Names: Give your rules meaningful names and descriptions for easier maintenance
- Set Appropriate Salience: Use salience values to control rule execution order (higher = higher priority)
- Organize Rules: Keep related rules in the same GRL file or JSON object
- Test Incrementally: Build and test simple rules first, then add complexity
- Reuse Binary Files: Compile rules once and reuse the .grb file for better performance
- Path Management: Use absolute paths for Rules Binary Path to avoid file location issues
- Version Control: Include rule files in version control to track changes over time
Common Errors and Solutions
Error: "Rules Binary Path cannot be empty"
Cause: The Rules Binary Path input is not provided or is empty.
Solution: Ensure you specify a valid file path for the output binary file.
msg.rulesPath = "C:/RPA/rules/my_rules.grb";
Error: "Rules cannot be empty"
Cause: The Rules input is not provided or is null.
Solution: Provide valid rule definitions in either GRL or JSON format.
Error: "Rules must be a JSON object but received string"
Cause: Rules Format is set to JSON, but the Rules input is a string instead of an object.
Solution: Either change Rules Format to GRL or provide a proper JSON object:
// Correct for JSON format
msg.rules = { "name": "MyRule", "when": "...", "then": [...] };
// Or use GRL format
msg.rules = "rule MyRule { when ... then ... }";
Error: "Rules must be a string for GRL format but received object"
Cause: Rules Format is set to GRL, but the Rules input is an object instead of a string.
Solution: Convert your rules to GRL string format or change Rules Format to JSON.
Error: "Failed to build rules"
Cause: The rule syntax is invalid or contains errors.
Solution:
- Check your GRL syntax for typos and syntax errors
- Ensure all rule names are unique
- Verify that conditions and actions are properly formatted
- Use proper data types in comparisons
Error: "Failed to create output file"
Cause: The specified path is invalid or the directory doesn't exist.
Solution:
- Verify the directory exists before running the Build node
- Use the File System package to create directories if needed
- Check file permissions
// Create directory first
msg.outputDir = "C:/RPA/rules";
// Then use it
msg.rulesPath = "C:/RPA/rules/my_rules.grb";
Best Practices
- Separate Rule Definition from Logic: Keep rule definitions in separate files or variables for easier maintenance
- Use Consistent Naming: Follow a naming convention for rules and facts
- Document Complex Rules: Add comments in GRL format using
//for single-line or/* */for multi-line - Validate Input Data: Ensure facts have expected properties before building rules that reference them
- Handle Edge Cases: Include rules for boundary conditions and exceptional scenarios
- Optimize Salience: Set higher salience for more specific rules and lower for general fallback rules