Overview
This article shows how you can use the North52 business rules engine for Microsoft Dynamics 365/Dataverse and the Azure Maps Get Search Address API to set Latitude and Longitude based on the address details of a Lead. It replaces the North52 GeoCodeBing function which has been discontinued by Microsoft.
North52 Decision Suite Solution
The North52 Decision Suite solution works like this:
- A Formula is set up on the Lead table which executes when address fields are changed:
- It calls the Azure Maps Get Search Address API using the CallRestAPI function and the address details
- JSON information is returned containing the Latitude and Longitude details
- North52 parses the JSON information and updates the Latitude and Longitude fields on the Lead table
Set up xCache
Store your Azure Maps subscription key securely with xCache.
- Open the North52 App
- Navigate to Business Process Activities > xCache
- Create a new xCache record
- Set the Category to AzureMaps
- Set the Base Key to AzureMaps_PrimarySubscriptionKey
- Set the Datatype to String (Password)
- Set the Value (Secured) to your Primary Subscription Key for Azure Maps
- Click Save
Set up Formula
- Open the North52 App
- Navigate to Business Process Activities > Formulas
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Lead
- Set Formula Type to Save Perform Action
- Select the Decision Table editor
- Change the Name of the formula to Lead - Save - Perform Action - Set Latitude and Longitude
- On the Register tab, expand Source & Target
- CTRL + Select the following: Street 1, City, Zip/Postal Code, Country/Region
- Click Save
- Set up the Conditions
- Select columns B, C, D then right-click and select Insert > Insert Condition
- Select cell A2, and from the Source tab select Source > Street 1
- Select cell B2, and select Source > City
- Select cell C2, and select Source > Zip/Postal Code
- Select cell D2, and select Source > Country Region
- Select cell A4, and from the Functions tab CTRL+click on the ContainsData function. This will enter {{{ContainsData}}} in the cell
- Copy cell A4, to B4, C4, and D4
- Select columns E, F, G then right-click and select Insert > Insert Inline Calculation
- Enter Address in E2
- In cell E4 we build up the full address required for the API using the Source tab to selected the columns:
[lead.address1_line1] + ', ' + [lead.address1_city] + ', ' +[lead.address1_postalcode] + ', ' + [lead.address1_country]
- In cell E4 we build up the full address required for the API using the Source tab to selected the columns:
- Enter FinalURL in F2
- In cell F4 we build up the URL that will be used in the CallRestAPI function in the next step, using the xCache value (AzureMaps_PrimarySubscriptionKey) for the subscription key, and the Address from the previous step for the query:
StringFormat('https://atlas.microsoft.com/search/address/json?&subscription-key={0}&api-version=1.0&language=en-US&query={1}', xCacheGetGlobal('AzureMaps_PrimarySubscriptionKey'), GetVar('Address'))
- In cell F4 we build up the URL that will be used in the CallRestAPI function in the next step, using the xCache value (AzureMaps_PrimarySubscriptionKey) for the subscription key, and the Address from the previous step for the query:
- Enter GetLatLong in G2
- In cell G4 enter (the SmartFlow() function allows us to set multiple variables within the SetRequestActionPass parameter):
CallRestAPI( SetRequestBaseURL(GetVar('FinalUrl')), SetRequestResource(''), SetRequestDetails('GET'), SetRequestHeaders(), SetRequestParams(), SetRequestAuthenticationNone(), SetRequestFiles(), SetRequestExpected('OK'), SetRequestActionPass( SmartFlow(SetVar('latitude', GetVarJsonValue('results[0].position.lat')), SetVar('longitude', GetVarJsonValue('results[0].position.lon'))) ), SetRequestActionFail(GetVar('responsecontent')) )
- In cell G4 enter (the SmartFlow() function allows us to set multiple variables within the SetRequestActionPass parameter):
- Select cell H2, and from the Source tab select Source > Address 1:Latitude
- In cell H4, enter GetVar('latitude')
- Select column I, then right-click and select Insert > Insert Action
- Select cell H2, and from the Source tab select Source > Address 1:Latitude
- In cell H4, enter GetVar('longitude')
- Click Save
Testing
Create or update a Lead record with a valid address and check the Latitude and Longitude fields have been updated: