CHALLENGE #2 - Geocode customers (LEVEL 3)

Scenario

As customers are created or modified, their addresses are automatically geocoded and their location are stored in a set of new fields on the Customer table. A factbox showing the current location of the customer on a map is added to the Customer Card and links to open a large map or get directions are available as well. As a bonus, you can create an action, which will display all customers within a certain range on a map.

To complete this challenge, you will need

  • A Dynamics 365 Business Central Sandbox Environment
  • Visual Studio Code with the AL Extension installed
    • Azure VMs will have VS Code pre-installed
  • A BingMaps API Key from https://www.bingmapsportal.com (Public WebSite or Dev/Test key)

Expected result

Steps

  • Create an empty app
  • Create a table extension for the customer table and add fields
  • Create a page extension for the customer card and add fields
  • On the OnBeforeModify and OnBeforeInsert triggers on the Customer table, geocode the customer address using BingMaps API
  • Create a CardPart page showing a map of the geocoded position
  • Create an action opening a browser with all customers as shared places

Hints

  • In VS Code, use Ctrl+Shift+P and type AL GO and remove the customerlist page extension
  • Use the ttableext, the tfield and the tkey snippets
  • Use the tpageext and the tpagefield snippets
  • Use HttpClient to communicate with the Web Service and use Json types (JsonObject, JsonToken, JsonArray and JsonValue) to extract values from the Web Service result
  • Use tpage snippet and add usercontrol with the WebPageViewer. Use https://www.bing.com/maps/embed-a-map to see the html you can use In the control.
  • Add location of all customers to the sp parameter as explained here: https://msdn.microsoft.com/en-us/library/dn217138.aspx

Cheat sheets

 

Happy coding

Freddy Kristiansen
Technical Evangelist

Passwords: Biza5514, Repe6676, Vady4574, Huwa2666, Dahi8208, Bamu6541, Xepe8513