Skip to main content

Execute

Executes a compiled rule set (Knowledge Base) against provided facts and returns the decision result. Facts represent objects in the rule engine's working memory that are evaluated against the rules.

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.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Facts - The data to evaluate against the rules. Can be either:

    • JSON Object: A single set of facts (standard mode)
    • JSON Array: Multiple sets of facts for time series analysis (when Time Series option is enabled)
  • Rules Binary Path - The path to the compiled binary Knowledge Base file (.grb) created by the Build node.

Output

  • Result - The decision result from rule execution. Contains the output values set by the rules. The structure depends on the execution mode:
    • Standard Mode: A JSON object with decision values
    • Time Series Mode: An array of JSON objects, one for each time period

Options

  • Time Series - When enabled, facts and results are treated as arrays for time series analysis. This mode provides access to technical analysis functions and iterates through time-based data.

Standard Mode Examples

Example 1: Basic Customer Discount Evaluation

This example evaluates customer data against discount rules:

// First, build your rules (using Build node)
msg.grlRules = `
rule VIPDiscount "VIP customer discount" {
when
customer.TotalPurchase >= 1000 && customer.IsMember == true
then
decision.Discount = 15;
decision.DiscountType = "VIP";
}

rule StandardDiscount "Standard discount" {
when
customer.TotalPurchase >= 500
then
decision.Discount = 10;
decision.DiscountType = "Standard";
}
`;

// Define the facts to evaluate
msg.facts = {
customer: {
TotalPurchase: 1200,
IsMember: true,
Name: "John Doe"
}
};

msg.rulesPath = "C:/RPA/rules/customer_discount.grb";

Execute Node Configuration:

  • Facts: {{msg.facts}}
  • Rules Binary Path: {{msg.rulesPath}}
  • Time Series: Unchecked
  • Result: {{msg.decision}}

Result:

// msg.decision will contain:
{
Discount: 15,
DiscountType: "VIP"
}

Example 2: Product Pricing Decision

Evaluate product data to determine pricing and shipping:

msg.grlRules = `
rule PremiumDiscount "Premium product discount" {
when
product.Category == "Electronics" && product.Price > 500
then
decision.FinalPrice = product.Price * 0.8;
decision.FreeShipping = true;
decision.DiscountApplied = "20% Premium Discount";
}

rule StandardPricing "Standard pricing" {
when
product.Price <= 500
then
decision.FinalPrice = product.Price;
decision.FreeShipping = product.Price > 100;
}
`;

msg.facts = {
product: {
Category: "Electronics",
Price: 750,
Name: "Wireless Headphones"
}
};

Result:

{
FinalPrice: 600,
FreeShipping: true,
DiscountApplied: "20% Premium Discount"
}

Example 3: Approval Workflow Logic

Determine approval requirements based on request data:

msg.grlRules = `
rule AutoApprove "Auto-approve small requests" salience 20 {
when
request.Amount <= 1000
then
decision.Approved = true;
decision.ApprovalLevel = "Auto";
decision.RequiresReview = false;
}

rule ManagerApproval "Manager approval required" salience 15 {
when
request.Amount > 1000 && request.Amount <= 5000
then
decision.Approved = false;
decision.ApprovalLevel = "Manager";
decision.RequiresReview = true;
}

rule DirectorApproval "Director approval required" salience 10 {
when
request.Amount > 5000
then
decision.Approved = false;
decision.ApprovalLevel = "Director";
decision.RequiresReview = true;
decision.EscalationRequired = true;
}
`;

msg.facts = {
request: {
Amount: 3500,
Department: "Finance",
Requestor: "Jane Smith"
}
};

Result:

{
Approved: false,
ApprovalLevel: "Manager",
RequiresReview: true
}

Time Series Mode Examples

Example 4: Stock Price Analysis

Analyze time series stock data to generate trading signals:

msg.grlRules = `
rule BuySignal "Generate buy signal" {
when
ta.Cross(prices, ma20) && ta.GTat(prices, ma50)
then
decision[t].Signal = "BUY";
decision[t].Confidence = "High";
}

rule SellSignal "Generate sell signal" {
when
ta.LTat(prices, ma20) && ta.LTat(prices, ma50)
then
decision[t].Signal = "SELL";
decision[t].Confidence = "Medium";
}
`;

// Define facts as arrays for time series
msg.facts = [
{
name: "prices",
data: [100, 102, 105, 103, 107, 110, 108, 112, 115, 118]
},
{
name: "ma20",
data: [98, 99, 100, 101, 103, 105, 106, 108, 110, 112]
},
{
name: "ma50",
data: [95, 96, 97, 98, 99, 100, 101, 102, 103, 104]
}
];

Execute Node Configuration:

  • Facts: {{msg.facts}}
  • Rules Binary Path: {{msg.rulesPath}}
  • Time Series: Checked
  • Result: {{msg.decision}}

Result: An array with one decision object per time period.

Example 5: CSV Data Time Series Analysis

Load data from CSV files for time series evaluation:

msg.grlRules = `
rule HighVolume "Detect high volume" {
when
ta.GTat(volume, volumeAvg) && ta.GTat(close, open)
then
decision[t].Alert = "High Volume Detected";
decision[t].Action = "Monitor";
}
`;

msg.facts = [
{
name: "volume",
path: "C:/RPA/data/stock_data.csv",
key: "Volume" // Column name in CSV
},
{
name: "volumeAvg",
data: [1000000, 1050000, 1100000, 1080000, 1120000]
},
{
name: "close",
path: "C:/RPA/data/stock_data.csv",
key: "Close"
},
{
name: "open",
path: "C:/RPA/data/stock_data.csv",
key: "Open"
}
];

CSV File Format (stock_data.csv):

Date,Open,Close,Volume
2024-01-01,100,102,1200000
2024-01-02,102,105,1150000
2024-01-03,105,103,1300000

Example 6: Technical Indicators

Use built-in technical analysis functions:

msg.grlRules = `
rule MomentumStrategy "Momentum-based strategy" {
when
ta.ChangeAt(close, 1) > 0 && ta.GTat(volume, threshold)
then
decision[t].Signal = "STRONG_BUY";
decision[t].Momentum = ta.ChangeAt(close, 1);
}

rule RangeBreakout "Detect range breakout" {
when
ta.GTat(high, resistance) && ta.GTat(volume, avgVolume)
then
decision[t].Breakout = true;
decision[t].Range = ta.Range(high);
}
`;

msg.facts = [
{
name: "close",
data: [100, 102, 105, 107, 110]
},
{
name: "high",
data: [102, 104, 107, 109, 112]
},
{
name: "volume",
data: [1000000, 1200000, 1500000, 1100000, 1800000]
},
{
name: "threshold",
data: [1000000, 1000000, 1000000, 1000000, 1000000]
},
{
name: "resistance",
data: [105, 105, 105, 105, 105]
},
{
name: "avgVolume",
data: [1200000, 1200000, 1200000, 1200000, 1200000]
}
];

Time Series Built-in Functions

The Execute node provides built-in libraries for time series analysis:

String Library (str)

  • str.Length(string) - Returns the length of a string

Technical Analysis Library (ta)

Available only in Time Series mode. Access current time index with t.

Math Operations

  • ta.Abs(value) / ta.AbsAt(array) - Absolute value
  • ta.Floor(value) / ta.FloorAt(array) - Floor function
  • ta.Round(value) / ta.RoundAt(array) - Round to nearest integer
  • ta.Max(v1, v2) / ta.MaxAt(arr1, arr2) - Maximum of two values
  • ta.Min(v1, v2) / ta.MinAt(arr1, arr2) - Minimum of two values

Comparison Operations

  • ta.LT(v1, v2) / ta.LTat(arr1, arr2) - Less than
  • ta.LTOE(v1, v2) / ta.LTOEat(arr1, arr2) - Less than or equal
  • ta.GT(v1, v2) / ta.GTat(arr1, arr2) - Greater than
  • ta.GTOE(v1, v2) / ta.GTOEat(arr1, arr2) - Greater than or equal
  • ta.EQ(v1, v2) / ta.EQat(arr1, arr2) - Equal
  • ta.NE(v1, v2) / ta.NEat(arr1, arr2) - Not equal

Logical Operations

  • ta.Not(bool) - Logical NOT
  • ta.And(b1, b2) - Logical AND
  • ta.Or(b1, b2) - Logical OR

Arithmetic Operations

  • ta.Plus(v1, v2) - Addition
  • ta.Minus(v1, v2) - Subtraction
  • ta.Mul(v1, v2) - Multiplication
  • ta.Div(v1, v2) - Division
  • ta.Mod(v1, v2) - Modulo

Technical Analysis Operations

  • ta.Lowest(array) - Returns lowest value in array
  • ta.Highest(array) - Returns highest value in array
  • ta.Range(array) - Returns range (highest - lowest)
  • ta.Cross(arr1, arr2) - Detects when two series cross
  • ta.Change(v1, v2) - Returns change between two values
  • ta.ChangeAt(array, periods) - Returns change over N periods
  • ta.SumAt(array, periods) - Returns sum of last N periods
  • ta.TrueRange(high, low, close) - Calculates true range
  • ta.Stoch(high, low, close, length) - Stochastic oscillator
  • ta.MomentumFlipDetectionAt(arr1, arr2) - Detects momentum changes
  • ta.DecreaseRatio(close, low, ratio) - Checks if decrease meets ratio

Tips

  1. Name Your Facts Clearly: Use descriptive names for facts that match your rule references
  2. Output Field Naming: The Result output field name should not conflict with any fact names
  3. Time Series Data Alignment: Ensure all arrays in time series mode have consistent lengths
  4. CSV Column Names: When using CSV files in time series mode, verify column names match the key property
  5. Rule Salience: Higher salience rules execute first - use this to prioritize important rules
  6. Test with Simple Facts: Start with simple fact objects before moving to complex nested structures
  7. Binary File Reuse: Compile rules once with Build node, then reuse the .grb file for multiple executions
  8. Performance: Binary Knowledge Base files (.grb) execute faster than compiling rules each time

Common Errors and Solutions

Error: "Rules Binary Path cannot be empty"

Cause: The Rules Binary Path input is not provided.

Solution: Provide the path to a compiled .grb file created by the Build node.

msg.rulesPath = "C:/RPA/rules/my_rules.grb";

Error: "Facts cannot be empty"

Cause: The Facts input is not provided or is null.

Solution: Provide valid facts as a JSON object (standard mode) or array (time series mode).

// Standard mode
msg.facts = { customer: { Amount: 1000 } };

// Time series mode
msg.facts = [
{ name: "prices", data: [100, 102, 105] }
];

Error: "Output Decision message field cannot be empty"

Cause: The Result output field is not mapped to a message property.

Solution: Configure the Result output to save to a message field.

Execute Node Configuration:

  • Result: {{msg.decision}}

Error: "Failed to open rules file"

Cause: The specified .grb file doesn't exist or the path is incorrect.

Solution:

  • Verify the file path is correct
  • Ensure the Build node has been executed successfully
  • Check that the .grb file exists at the specified location

Error: "Facts must be a JSON object but received array"

Cause: Time Series option is unchecked, but facts are provided as an array.

Solution: Either enable Time Series option or provide facts as a JSON object.

// For standard mode (Time Series unchecked)
msg.facts = {
customer: { Amount: 1000 }
};

// For time series mode (Time Series checked)
msg.facts = [
{ name: "prices", data: [100, 102, 105] }
];

Error: "Facts must be a JSON array for time series mode but received object"

Cause: Time Series option is checked, but facts are provided as an object instead of an array.

Solution: Provide facts as an array of fact objects when Time Series is enabled.

msg.facts = [
{ name: "prices", data: [100, 102, 105] },
{ name: "volume", data: [1000, 1200, 1100] }
];

Error: "Each fact must have a 'name' property"

Cause: In time series mode, one or more fact objects are missing the name property.

Solution: Ensure each fact object has a name property.

msg.facts = [
{ name: "prices", data: [100, 102, 105] }, // ✓ Correct
{ data: [1000, 1200, 1100] } // ✗ Missing 'name'
];

// Fix:
msg.facts = [
{ name: "prices", data: [100, 102, 105] },
{ name: "volume", data: [1000, 1200, 1100] } // ✓ Correct
];

Error: "Each fact must have either 'path' or 'data' property"

Cause: In time series mode, a fact object has neither path nor data property.

Solution: Each fact must have either data (array) or path (CSV file path).

// Using data property
{ name: "prices", data: [100, 102, 105] }

// Using path property
{ name: "volume", path: "C:/data/stock.csv", key: "Volume" }

Error: "Fact path must be a CSV file"

Cause: The path property points to a non-CSV file.

Solution: Only CSV files are supported for time series data. Use .csv files.

// Incorrect
{ name: "data", path: "C:/data/stock.xlsx", key: "Price" }

// Correct
{ name: "data", path: "C:/data/stock.csv", key: "Price" }

Error: "Invalid column name"

Cause: The key property specifies a column name that doesn't exist in the CSV file.

Solution: Verify the column name matches exactly (case-sensitive) with the CSV header.

Date,Open,Close,Volume
// Incorrect
{ name: "prices", path: "stock.csv", key: "Price" } // Column doesn't exist

// Correct
{ name: "prices", path: "stock.csv", key: "Close" } // Column exists

Error: "Fact name cannot be the same as the output message field name"

Cause: A fact has the same name as the output field (e.g., both named "decision").

Solution: Rename either the fact or change the output field name.

// Incorrect - if output is msg.decision
msg.facts = {
decision: { value: 100 } // Same name as output
};

// Correct
msg.facts = {
input: { value: 100 } // Different name
};

Error: "Failed to execute rules"

Cause: A rule encountered an error during execution (e.g., accessing undefined properties).

Solution:

  • Ensure all properties referenced in rules exist in the facts
  • Check for null or undefined values in fact data
  • Verify rule logic is correct
  • Add defensive checks in rules
// Risky rule
rule CheckValue {
when
customer.Address.City == "New York" // May fail if Address is undefined
then
decision.Discount = 10;
}

// Safer rule
rule CheckValue {
when
customer.Address != nil && customer.Address.City == "New York"
then
decision.Discount = 10;
}

Best Practices

  1. Validate Facts: Ensure your facts contain all properties referenced in your rules
  2. Handle Missing Data: Include rules to handle cases where expected data might be missing
  3. Use Meaningful Output Names: Name your decision outputs clearly (e.g., msg.approvalDecision, msg.pricingResult)
  4. Time Series Data Quality: Ensure arrays are the same length and properly aligned by time
  5. CSV Data Validation: Verify CSV files have consistent column names and data types
  6. Test with Sample Data: Test rules with various fact combinations to ensure correct behavior
  7. Monitor Performance: For large time series datasets, consider breaking into smaller batches
  8. Error Handling: Use Continue On Error option when appropriate, and handle decision results that may be empty
  9. Rule Execution Order: Remember that rules with higher salience execute first
  10. Fact Immutability: Original facts are not modified; results are written to the decision output