Address Prediction API
Codeunit 5523621 bdev.Address Prediction API drives the type-ahead: while the user types into a bound field, the app offers matching addresses, and picking one hands you the address in structured form.
Version
The Address Prediction API has been introduced with 365 business Address Validation 18.9.
Prediction needs three things on your page:
- the
bdev.Address Autocompletecontrol add-in, which does the typing and the suggestion list in the browser; - the codeunit, which connects the control to the prediction service;
- for a table of your own, a subscriber to OnIsAddressPredictionEnabledForTableNo.
The page: putting it together
The control add-in is one pixel in size and carries no UI of its own - it attaches to the fields you bind to it. A page that offers prediction looks like this:
Code
Bind on every record change
The binding lives in the control, not in the record. Bind in OnAfterGetRecord and in OnNewRecord, or the type-ahead stops working as soon as the user moves to another record or creates one.
InitializeAddressPrediction()
Resets the prediction instance. Call it in OnOpenPage, before anything else.
Code
OnControlAddInReady(Integer, ControlAddIn)
Activates the control once the browser has loaded it, and states which table the page shows.
Code
| Parameter | Type | Description |
|---|---|---|
tableNo | Integer | The table id of the page source. Decides whether prediction is enabled - see Extensibility Events. |
control | ControlAddIn "bdev.Address Autocomplete" | The control of the current page. |
Call it from the OnControlReady trigger of the control and from nowhere else - the control is not ready before.
BindAddressPrediction(...)
Binds page fields to the type-ahead. Four overloads, differing only in how much you say about each field:
Code
| Parameter | Type | Description |
|---|---|---|
fieldName / fieldNames | Text, List or Dictionary | The field name as the page knows it. Use Rec.FieldName(...) rather than a literal, so a rename cannot break the binding silently. |
addrPreditionType | Enum "bdev.Address Prediction Type" | Address or Establishment. The overloads without it bind as Address. |
control | ControlAddIn "bdev.Address Autocomplete" | The control of the current page. |
Binding a field that is already bound rebinds it - the codeunit unbinds it first - so calling the binding again on every record change is safe.
UnbindAddressPrediction(Text, ControlAddIn)
Removes the type-ahead from a field, for example when your page turns it off for a record.
Code
GetAddressPredictions(Text, Text, ControlAddIn)
Fetches the suggestions for the current input and hands them to the control, which shows them.
Code
| Parameter | Type | Description |
|---|---|---|
fieldName | Text | The field the user is typing into, as passed by the trigger. |
input | Text | What the user has typed so far. |
control | ControlAddIn "bdev.Address Autocomplete" | The control of the current page. |
Call it from the GetAddressPredictions trigger of the control. It fires on every keystroke, so do not put work of your own around it.
GetSelectedAddressPrediction(Dictionary, Enum, Text)
Resolves the suggestion the user picked into the address behind it.
Code
| Parameter | Type | Description |
|---|---|---|
address | Dictionary of [Text, Text] | The address of the suggestion. |
addressType | Enum "bdev.Address Prediction Type" | The type the field was bound as. GetAddressType answers it for a field name. |
id | Text | The id of the suggestion, as passed by the trigger. |
Returns false when the address could not be fetched.
The dictionary carries the parts of the address the service knows. Not every key is present - a rural address without a street number has no address, and the business keys only appear for an Establishment. Ask with ContainsKey before reading:
| Key | Content |
|---|---|
address | Street and house number. |
address2 | Additional address information. |
city | City. |
postalCode | Post code. |
county | Region, state or county. |
countryCode | ISO alpha-2 country code. |
companyName | Name of the business. Establishment only. |
phoneNumber | International phone number. Establishment only. |
homePage | Website, reduced to the domain. Establishment only. |
Code
Validate Country/Region Code first: the format of the other fields depends on the country.
GetAddressType(Text)
Returns the type a field was bound as, so that the selection trigger can pass it on without keeping its own state.
Code
See also
- 365 business Address Validation - Overview
- Extensibility Events
- Address Validation API
- Documentation - Address Prediction


