Codeunit 18008311 EOS010 Advanced Calc Filter

Codeunit 18008311 EOS010 Advanced Calc Filter

Codeunit for advanced filtering optimization in commission calculation. This codeunit provides an optimized filtering mechanism for the EOS Commissions Calc. Setup table by using SetID fields and caching strategies to improve performance when searching for matching commission calculation setup records.

Key features:

  • SingleInstance design pattern for persistent caching across calls
  • Manual event subscription for table insert/modify/delete/rename events
  • Regex-based detection of complex filter expressions (wildcards, ranges, operators)
  • Multi-level caching: filter values, lookup table values, regex matches, and filter match results
  • Automatic cache invalidation with 60-second throttling to balance freshness and performance
  • Integration with EOS010 Filter Value Lookup table for unique ID assignment

Usage:

  1. Call BindCodeunit() to activate event handling
  2. Use SetAdvancedFilters() to apply optimized filters to commission setup queries
  3. Call UnBindCodeunit() when event handling should be disabled

The caching strategy:

  • FilterValueCache: Maps field numbers to dictionaries of filter values
  • FieldHasComplexFilter: Tracks which fields contain complex filter expressions
  • LookupValueCache: Maps text values to their unique IDs in the lookup table
  • RegexMatchCache: Caches regex evaluation results for filter complexity detection
  • FilterMatchCache: Caches filter match results for value-filter combinations

Methods

IsAdvanceFilteringEnabled

procedure IsAdvanceFilteringEnabled(): Boolean

Checks if advanced filtering optimization is enabled in the commissions setup.

Parameters / Return Value

  • Returns Boolean

    True if advanced filtering is enabled, false if disabled or when optimization is turned off


SetAdvancedFilters

procedure SetAdvancedFilters(var CommissionsCalcSetup: Record "EOS Commissions Calc. Setup";CommissionsCalcSetupFieldNo: Integer;FilterValue: Text): Boolean

Applies a SetID filter to the Commissions Calc. Setup record based on the field number and filter value.

Parameters / Return Value

  • CommissionsCalcSetup Record "EOS Commissions Calc. Setup"

    The record to apply the filter to

  • CommissionsCalcSetupFieldNo Integer

    The field number from EOS Commissions Calc. Setup table

  • FilterValue Text[]

    The filter value to match against

  • Returns Boolean


InvalidateCache

procedure InvalidateCache()

Invalidate the internal cache of complex filter fields. It’s done automatically when the setup is modified and every 60 seconds. Note: LookupValueCache is NOT cleared here because the lookup table only grows (records are never deleted/modified).


TryIsFilterMatch

procedure TryIsFilterMatch(Value: Text; filter: Text; var Result: Boolean)

Tries to check if a value matches a filter expression with exception handling. This is a safe wrapper around IsFilterMatch that catches any exceptions and returns false without raising an error. Uses a cache to avoid repeated evaluations of the same value-filter combinations.

Parameters / Return Value

  • Value Text[]

    The value to check

  • filter Text[]

  • Result Boolean

    The result of the filter match check (true if the value matches the filter)


IsFilterMatch

procedure IsFilterMatch(Value: Text; filter: Text): Boolean

Checks if a value matches a filter expression. Uses a cache to avoid repeated evaluations of the same value-filter combinations.

Parameters / Return Value

  • Value Text[]

    The value to check

  • filter Text[]

  • Returns Boolean

    True if the value matches the filter, false otherwise


PopulateRecordSetIDs

procedure PopulateRecordSetIDs(var CommissionsCalcSetup: Record "EOS Commissions Calc. Setup")

Populates the “*SetID” fields for a single record. Uses the EOS010 Filter Value Lookup table to get or create unique IDs for each value.

Parameters / Return Value

  • CommissionsCalcSetup Record "EOS Commissions Calc. Setup"

    The record to populate SetID fields for



EOS Labs -