Scenario Overview
In this scenario you need to implement a business rule that will Geo-Encode all the addresses within your Microsoft Dynamics 365 Account entity. This involves using the data within the following fields on the account entity to set the correct longitude & latitude fields on the account entity.
- address1_line1
- address1_city
- address1_stateorprovince
- address1_postalcode
- address1_country
North52 uses Microsoft's Bing geo-encoding service to retrieve the required data & you will need a Microsoft account. This must be configured within the North52 Configuration entity. Click here for more details.
North52 Decision Suite Solution
The North52 Decision Suite solution works like this,
- Use the ForEachRecord() function to loop over the set of accounts
- We define the set of account records we want to loop over by using the FindRecords() function & we just use '*' to indicate all records.
- When we start to loop on the account records we need to define the action that will happen for each record,
- First use the GeoCodeBing() function to retrieve the data from Microsoft.
- Now store that result in a variable called 'Result'
- Finally as part of the SmartFlowReturn, call the UpdateRecord() function which sets the longitude & latitude on the account entity.
North52 Decision Suite Steps
The following set of steps outline how to create this Formula
- Create a new formula of type N52 Command
- Copy & paste the formula below into the formula description field
- Click save
- Now you are ready to execute the formula against your CRM system. You can do this by clicking the execute button (second last button, on the button list within the formula editor).
- It will ask you are you sure. Click Ok & the command will execute.
- When the command completes it will tell you it was successful so you can now go check your account entity to see that the first 50 account records have been geo-encoded
Formula
ForEachRecord( FindRecords('account', '*', '*', '*', 50), SmartFlow ( SetVar('Result', GeoCodeBing(CurrentRecord('address1_line1'), CurrentRecord('address1_city'), CurrentRecord('address1_stateorprovince'), CurrentRecord('address1_postalcode'), CurrentRecord('address1_country'))), SmartFlowReturn( if (GetVar('Result') = '', 'NoOp', UpdateRecord('account', CurrentRecord('accountid'), SetAttribute('address1_latitude', Split(GetVar('Result'), '|', 0)), SetAttribute('address1_longitude', Split(GetVar('Result'), '|', 1)) ) ))) )