I am excited to share with you some of the new features now that FileMaker 16 has officially been released.  In this post I thought I would start out simple and show the JSON parsing function coupled with a simple API call which allows for simpler data entry when it comes to entering in an address.

Many of you have probably visited websites where you can start entering in an address and a list of predicted addresses appear.  The more text you enter in the provided field the closer you get to the address you are looking for.  This is the same technique you can use when implementing the Google Places AutoComplete API.

Address Auto Complete

Address Auto-Complete allows a user to type in an address, the auto-complete function will then return a list of possible matching addresses. If the user sees a matching address they can click on it and populate the info into the appropriate fields.

How It Works

There is an “On_Modify_Script” trigger on the “Address_Street” field. The script runs when the text field character length reaches 7, then again at 13 and also at greater than 16.  The script exits immediately if City and State are populated.

Initial Trigger

Second Trigger

Address Selected

When the script is triggered, it makes an API call to Google’s Places Auto-Complete service and stores the result to the variable $$addressResult.  In the virtual list table there are 5 records which represent the 5 records Google returns with the API call.  Each field has a calc that grabs the appropriate field from the global variable and saves it.

Database Model

When the $$addressResult variable is not empty, a hidden portal appears with up to 5 potential matching addresses. When the user clicks on the address they want, it copies over the data from the matching virtual list record to the contact record fields.

Initial Set Fields Script

In order to use this feature you will need to setup a Google developer account and authorize the Google Places API. Then you will need to add the key to the Trigger | On First Window Open script.

Special Notes

Google sends the predictions back in two different formats which require special handling of the JSON parsing. If you look at the virtual list table, the field ‘numOrFullStreet’ determines which of the 2 formats the particular record represents. The different formats relate to the first “term” google returns for a record. Sometimes it is just the street number. In other cases it is the street number and street. It is only defined once by Google as “term”.

JSON Terms

Further Terms

In addition to this, the AutoComplete API does not provide the postal code. Once the user selects the address, an additional API call is made to Google Places for the postal code based on the ‘place id’ associated with the address.  With this being the case I used the ‘Set Fields’ script to show the JSON parsing of the address directly in the script.

Full Set Fields Script

The visuals provided show the intricacies of working with these API’s and the ‘Set Fields’ script.

Please fill out the below form for a downloadable FM16 of the above example.

I hope you all enjoy the rest of your week and feel free to email with any questions.

– Brian

Brian Ouimette
The Scarpetta Group, Inc.