New Zealand Post Auto-complete in Dynamics 365

John Towgood, 10 May 2017

The auto-complete control is a great feature in Dynamics CRM 365 to display a list of suggested text values as you type. In older Dynamics CRM versions, unsupported JavaScript or a web resource would have been required to achieve this Auto-complete functionality.

image

The following steps demonstrate how to use the Auto-complete control to display address suggestions from the New Zealand Post Address API:

1.    Obtain New Zealand Post Client Id and Secret

When you register with New Zealand Post and set up your free account, a Client Id and Client Secret would be generated which will be used in every HTTP request to the New Zealand Post Address API

2.    Setup the on key press event

Bind the on key press event of a single-line text field. This converts the single-line of text control to an Auto-complete control.

image

3.    Pass the input text value on every key press

For every key press against the field obtain the field value and pass to the getSuggestions() function

image
4.    Generate API Query string

Generate the New Zealand Post API query string by concatenating the New Zealand Post API URL, Client Id, Client Secret and field value.

image
5.    Retrieve Address Suggestion from the New Zealand POST API

Send a HTTP request to the New Zealand POST API and process the response. A successful HTTP Status 200 response will contain JSON data which is parsed and added to an array of Address Suggestion objects.

image
6.    Populate the auto-complete control with the array of Address Suggestion objects

image

That’s all there is to it. A small amount of work to improve the user experience and also ensure that accurate address data is stored in your Dynamics 365 system.