Administration, Dynamics CRM, Field Service

Setting the Geocode for accounts with a workflow

Each account in crm has the default fields address1_latitude and address1_longitude. These fields can be filled manually or via a tool, connecting a service provider like google maps or Bing maps.

With the field service module, you already have Bing maps included. To enable the automatic filling, navigate to Field service > Administration > Field Service Settings. Search for “Auto Geo Code Addresses” and set this to “YES” (the internal name of the field is msdyn_autogeocodeaddresses).

After enabling the Auto Geocode, there will be a popup while entering the address on the account form. The system will offer you possible matches based on the entered address. If you click on one of the offered matches, the latitude and longitude will automatically be filled out.

Popup windows while entering the address on the account form
Popup windows while entering the address on the account form

But what can you do, if you import an account via the API and these fields should also be filled out?

You can create a workflow, which calls the same method, as this method is offered via an action.

Follow these steps:

  1. Create a workflow that will be triggered on the creation of the account and on the modification of the required fields like street, city, postal code …
    Creating a workflow to set the geocode
    Creating a workflow to set the geocode

     

  2. Add a Step “Perform action” and select the “Resource Scheduling – Geocode Address”. Click on “Set Properties” and define the fields, based on your selected entity. The action requires many fields. If you haven’t all information, you can just put a “-“ in it. Beware, that this might end in a different coordinates, as if you are not providing the street, the coordinates might only be the middle of the provided city.
    Required fields of the action
    Required fields of the action

     

  3. Add an update-step and put in the result of the action and save the account.

Now run your workflow and check, if all is correct.

 

You might get an error like “Input string was not in a correct format.” Checking the full log shows, that there is a problem with parsing a string to a double.

To fix this issue, you first have to know, how the Bing maps API is working. CRM calls the URL https://dev.virtualearth.net/REST/v1/Locations?q=…&c=….&o=xml&key=……

Parameters:

  • q = the street, city, postal code, …
  • c = the language code (LCID)
  • o = output format
  • key = your key that authenticates you

For example:

https://dev.virtualearth.net/REST/v1/Locations?q=4020, Linz&c=1031&o=xml&key=???????

The results looks like this:

As you can see, the coordinates are in an English format. The parameter c is used, to put in the language code, but changing this, the result is always the same.

If your Async-User on your backend server is not configured with the culture English, the action can’t convert the coordinates to a valid double. Therefore change the locale of the user to English and the error is fixed and your workflow will work as expected. Also the App-Pool-User on the frontend servers has to use the english format.