> For the complete documentation index, see [llms.txt](https://coldbox-orm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-orm.ortusbooks.com/v5.x/criteria-queries/criteria-builder/interception-events.md).

# Interception Events

The criteria interception points and how cborm relays them to ColdBox interceptors

The criteria builder announces interception points when conditions are added and when `list()`, `count()` and `get()` run. You can listen to them to log, audit or tweak criteria queries across your application.

| Interception point           | When                                 | Data                                             |
| ---------------------------- | ------------------------------------ | ------------------------------------------------ |
| `onCriteriaBuilderAddition`  | A condition is added                 | `criteriaBuilder`, `type` (the condition method) |
| `beforeCriteriaBuilderList`  | Before `list()` runs                 | `criteriaBuilder`                                |
| `afterCriteriaBuilderList`   | After `list()` runs                  | `criteriaBuilder`, `results`                     |
| `beforeCriteriaBuilderCount` | Before `count()` runs                | `criteriaBuilder`                                |
| `afterCriteriaBuilderCount`  | After `count()` runs                 | `criteriaBuilder`, `count`                       |
| `beforeCriteriaBuilderGet`   | Before `get()` or `getOrFail()` runs | `criteriaBuilder`                                |
| `afterCriteriaBuilderGet`    | After `get()` or `getOrFail()` runs  | `criteriaBuilder`, `result`                      |

The `type` of `onCriteriaBuilderAddition` is the condition's main name, so `eq()` is reported as `isEq`. A negated condition is reported with its full name, for example `notLike`.

## How cborm relays them

bx-orm announces these points on the BoxLang runtime. cborm registers them as ColdBox custom interception points and, when the module loads, registers a small bridge (`cborm.models.CriteriaEventBridge`) that re-announces each one to the ColdBox interceptor service. Your ColdBox interceptors listen to them as usual:

```javascript
// interceptors/CriteriaAudit.bx
class {

    property name="log" inject="logbox:logger:{this}";

    function onCriteriaBuilderAddition( event, data ){
        log.debug( "Criteria condition added: #data.type#" );
    }

    function afterCriteriaBuilderList( event, data ){
        log.debug( "Criteria list returned #data.results.len()# rows: #data.criteriaBuilder.getSQL()#" );
    }

}
```

```javascript
// config/ColdBox.bx
interceptors = [
    { class : "interceptors.CriteriaAudit" }
];
```

Because bx-orm announces the points for every criteria, they fire for criteria created with `newCriteria()` and for criteria created directly with `entityCriteria()`. Plain BoxLang interceptors registered on the runtime (`boxRegisterInterceptor()`) receive them too.

{% hint style="info" %}
**Changes from cborm 5**

* The interception point names and data keys are the same, but `criteriaBuilder` is now the bx-orm criteria builder.
* `onCriteriaBuilderAddition` fires for conditions only, and its `type` is the condition method (`isEq`, `like`, `notIn`, ...). In cborm 5 it was a category (`Restriction`, `Subquery`, `Offset`, `Max`, ...) and also fired for `firstResult()` and `maxResults()`.
* In cborm 5 the cborm criteria builder announced them directly to ColdBox; in cborm 6 bx-orm announces them and cborm's `CriteriaEventBridge` relays them. The bridge is removed when the cborm module unloads.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-orm.ortusbooks.com/v5.x/criteria-queries/criteria-builder/interception-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
