# Pre Advices

![](/files/-LDgKR6YV9Zn3xnEzebZ)

With this interceptor you can intercept local event actions and execute things **before** the requested action executes. You can do it globally by using the `preHandler()` method or targeted to a specific action `pre{actionName}()`.

```javascript
// executes before any action
function preHandler( event, rc, prc, action, eventArguments ){
}

// executes before the list() action ONLY
function preList( event, rc, prc, eventArguments ){
}

// concrete example
function preHandler( event, rc, prc, action, eventArguments ){
    if( !security.isLoggedIn() ){
        event.overrideEvent( 'security.login' );
        log.info( "Unauthorized accessed detected!", getHTTPRequestData() );
    }
}
function preList( event, rc, prc, eventArguments ){
    log.info("Starting executing the list action");
}
```

The arguments received by these interceptors are:

* `event` : The request context reference
* `action` : The action name that was intercepted by `preHandler()`
* `eventArguments` : The struct of extra arguments sent to an action if executed via `runEvent()`
* `rc` : The **RC** reference
* `prc` : The **PRC** Reference

Here are a few options for altering the default event execution:

* Use `event.overrideEvent('myHandler.myAction')` to execute a different event than the default.
* Use `event.noExecution()` to halt execution of the current event. ONLY works when executed by interceptions before the main event. It will never work in pre/post advices.

See the [RequestContext](/the-basics/request-context.md) documentation for more details.

## Exceptions & Only Lists

You can fine tune these interception methods by leveraging two public properties in the handler:

* `this.prehandler_only` : A list of actions that `preHandler()` will ONLY fire on
* `this.prehandler_except` : A list of actions that `preHandler()` will NOT fire on

```javascript
// only fire for the actions: save(), delete()
this.prehandler_only = "save,delete";
// DO NOT fire for the actions: login(), doLogin(), logout()
this.prehandler_except = "login,doLogin,logout"
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coldbox.ortusbooks.com/the-basics/event-handlers/interception-methods/pre-advices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
