import { Callout } from "zudoku/ui/Callout";

# Extensibility Events

`365 business Address Validation` publishes one event another extension can subscribe to. It decides whether the address prediction runs for a table the app does not know.

| Codeunit | Event | Raised |
| --- | --- | --- |
| `bdev.Address Prediction API` (`5523621`) | [`OnIsAddressPredictionEnabledForTableNo`](#onisaddresspredictionenabledfortableno---event) | When a page activates the prediction control for a table the app does not support itself. |

<Callout type="info" title="Why there is only one">
The app publishes further events, but they sit on codeunits marked `Access = Internal` and cannot be reached from another extension. What they offer is available in a supported form elsewhere: to validate a record of your own, call the [Address Validation API](address-validation-api.mdx) rather than waiting for the app to come to you.
</Callout>

## OnIsAddressPredictionEnabledForTableNo - Event

The event is raised for every table **except** the ones the app supports itself - `Contact`, `Customer`, `Vendor`, `Employee`, `Resource`, `Sales Header` and `Ship-to Address`, each of which has its own switch in `Address Validation Setup`. Subscribe to it to switch the type-ahead on for a table of your own.

It is only reached when address prediction is enabled in the setup at all and the feature is licensed. A subscriber answering `true` therefore enables the prediction for your table, but does not turn the feature on.

```pascal
    /// <summary>
    /// The event is executed for every table that is not supported by the
    /// Address Validation app itself. Use this to enable execution for your own tables.
    /// </summary>
    /// <param name="tableNo">Table No.</param>
    /// <param name="enabled">Specifies whether to enable Address Prediction or not.</param>
    [IntegrationEvent(false, false)]
    local procedure OnIsAddressPredictionEnabledForTableNo(tableNo: Integer; var enabled: Boolean)
    begin
    end;
```

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `tableNo` | Integer | The table id the page passed to `OnControlAddInReady`. |
| `enabled` | Boolean | Set to `true` to run the prediction for this table. |

### Example

```pascal
codeunit 50000 "My Address Prediction Subscriber"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"bdev.Address Prediction API", 'OnIsAddressPredictionEnabledForTableNo', '', true, true)]
    local procedure EnableBrokerOnIsAddressPredictionEnabledForTableNo(tableNo: Integer; var enabled: Boolean)
    begin
        if (tableNo = Database::Broker) then
            enabled := true;
    end;
}
```

<Callout type="caution" title="Only ever switch it on">
Several extensions can subscribe to this event, and they see each other's answer. Set `enabled := true` for the tables that are yours, and leave the parameter alone for every other table id - `enabled := (tableNo = Database::Broker)` would switch off the prediction another extension had just enabled.
</Callout>

Without a subscriber that answers `true`, the prediction control on a page of your own loads but never offers a suggestion. That is the usual explanation for a type-ahead that stays silent.

## See also

- [365 business Address Validation - Overview](readme.mdx)
- [Address Prediction API](address-prediction-api.mdx)
- [Address Validation API](address-validation-api.mdx)
