In this business scenario we want to update the longitude and latitude of an Account whenever there is a change made to the Account's address.

We can do this by using North52's CallRestAPI function along with the Google Geocoding API service.

Note you will need an API key from a Google Maps Platform account that has the Geocoding API enabled. Click here for more details.

North52 BPA Solution

The North52 BPA solution works like this:

  • A Formula is set up that triggers whenever one of the Account's address fields are changed
    • This formula will make an API call to the Geocoding API service using the address values and an xCache record that stores your Geocoding API key
    • The formula will then interpret the response from the Geocoding API
      • If the response contains a longitude and latitude, the formula will then update the longitude and latitude of the Account
      • If the response does not contain a longitude and latitude, the formula will then update the description field to Longitude and Latitude not found

Set up xCache and Formula


To securely store the API ID we use an xCache record. Only System Administrators or specifically authorized users will be able to access this value.

  • Navigate to Settings > North52 BPA > N52 xCache
  • Create a new xCache record
    • Enter Geocoding for the Category
    • Add AppID to the Base Key so that the full BaseKey name is Geocoding_AppID
    • In the Value Information tab enter your Google Maps Platform API ID into the Value (Secured) field
  • Click Save


  • Navigate to Settings > North52 BPA > N52 Formula
  • Create a new formula, setting the following values in the Formula Guide:
    • Set Entity to Account
    • Set Formula Type to Save - Perform Action
    • Set Editor to Classic
  • Click Create
  • Change the Name of the formula to Find longitude and latitude using Googles Geocoding API
  • Expand Source & Target
    • Under Source Property, select the following fields. Note you multi-select fields by holding down Ctrl when clicking. 
      • Address 1 : City , Address 1 :  Country/Region , Address 1 : State/Province, Address 1 : County, Address 1 : Street 1, Address 1 : Street 2, Address 1 : Street 3
  • Copy the following formula into the editor:
            [account.address1_line1]+ ' ' 
            +[account.address1_line2] + ' ' 
            +[account.address1_line3] + ' ' 
            +[account.address1_city] + ' ' 
            +[account.address1_county] + ' ' 
            +[account.address1_stateorprovince] + ' ' 
            'key',xCacheGetGlobal('Geocoding_AppID') ),  
      If(GetVarJsonValue('status') = 'REQUEST_DENIED' ,      
          SetAttribute('description', 'Error : Longitude and Latitude not found using address' )
        ) ,   
          SetAttribute('address1_latitude', GetVarJsonValue('results{0}')),
          SetAttribute('address1_longitude', GetVarJsonValue('results{0}.geometry.location.lng'))
  • Click Save


To test this formula, simply create or update an Account's address fields.

Note you may need to add the fields longitude and latitude to the Account form. 


Did you know?

North52 has a powerful distributed cache for advanced decision logic

xCache allows you to configure and scale your Dynamics 365/CRM applications running On-Premise or Online. It allows dynamic system configuration and removes performance bottlenecks related to data storage. xCache provides Dynamics 365/CRM with an extremely fast and scalable distributed cache to power your advanced decision logic.

xCache in Dynamics CRM  lets you cache static application data, and also load dynamic cache items for applications running in a single or multi-server configuration.

Learn more and see examples of xCache