Search FlexiRule docs

Recent
Pinned

Press Esc to close. Use arrow keys and Enter inside results. Searches are remembered locally.

FlexiRule Docs

Query Records

Find and use information from your system to support business logic.

Improve this page

Query Records#

Query Records is a rule execution block that retrieves data from the system’s database or reporting layer. It acts as a read-only data access layer, enabling rules to read external context beyond the triggering document and use that data for decisions, calculations, and automation.


Core Principles#

  • Read-Only: Query Records never mutates (changes) data. It is dedicated exclusively to finding and retrieving information.
  • Downstream Consumption: It produces structured outputs that are designed to be consumed by downstream rule blocks, including:
    • Conditions (Check): To drive branching logic.
    • Loops: To process multiple records in bulk.
    • Calculations: To enrich data for mathematical operations.
    • Assignments (Set Value): To update the current document with retrieved information.

When to Use#

You should use a Query Records block whenever a rule needs context from the rest of your system:

  • Validation: “Does a record with this reference number already exist?”
  • Enrichment: “What is the credit limit for this customer?”
  • Calculations: “What is the total value of all open invoices for this supplier?”
  • Batch Processing: “Find all overdue tasks to trigger follow-up actions.”

Available Query Modes#

FlexiRule supports several retrieval modes, allowing for flexible data access depending on your needs.

ModeOperation TypePrimary Use Case
Exist RecordExistence CheckQuickly check if a record exists.
Query DocSingle-Record RetrievalRetrieve a single record with its full details.
Query ListMulti-Record RetrievalRetrieve multiple records matching criteria.
CountAggregationGet the total number of matching records.
SumAggregationCalculate the total of a numeric field.
AverageAggregationCalculate the average of a numeric field.
Min / MaxAggregationFind the lowest or highest value in a group.
Group ByAggregationSummarize data organized by category.
Query ReportReport ReuseReuse results from an existing system report.

Performance & Execution Model#

To maintain system responsiveness, FlexiRule utilizes several execution strategies. Understanding these helps in building high-performance rules.

1. Database-Level Aggregation#

Modes like Count, Sum, Average, and Min/Max use “pushdown” optimization. Instead of loading every record into the rule engine, the system performs the calculation directly at the database level. This reduces data transfer and memory usage.

2. Intelligent Caching#

The Query Doc mode supports a cached retrieval strategy. When enabled, the system attempts to fetch the record from memory rather than the database. This is efficient for master data (like Customers or Items) that is frequently read but rarely changed.

3. Lightweight Existence Checks#

Exist Record is the most efficient check. It stops searching as soon as it finds a single match and does not load any field data. Use this mode whenever you only need a Yes/No answer.

4. Data Volume Control#

Rules should always use Filters to narrow the search scope. For list-based queries, always define a Result Limit to prevent the rule from attempting to process unexpectedly large datasets.


Best Practices#

  • Filter Early: Be as specific as possible in your filter criteria.
  • Minimize Field Fetching: Only select the specific fields required for your logic.
  • Use Aggregations: Prefer Count or Sum over fetching a list and looping to calculate totals.
  • Monitor Reports: When using Query Report, remember that the rule performance depends entirely on the report’s efficiency.
Query Doc Find one specific item and retrieve its details. Query List Find multiple records matching specific criteria. Exist Record Check if a record exists without retrieving data. Query Report Retrieve data using an existing system report. Count Determine the total number of records matching your criteria. Sum Calculate the total of a numeric field across multiple records. Average Calculate the mean value of a numeric field. Min / Max Retrieve the smallest or largest value from a group of records. Group By Summarize and categorize data into grouped results.