Custom Function to get Time Zone from Google Cloud

Custom Function to get Time Zone from Google Cloud

Guys, wanted to post what I had to do to get my time zone filed (custom field in my leads module) to go out and get the timezone based on the zip code of the lead.

1 Create a Google Cloud Account
2 Create an API Key and also make sure API functions for geocode and timezone is added to your account

3 Create a new custom function with 2 params:

leadid (string)
zip (string

4 Look up the ZOHO API object names (2nd column) in zoho, using these links below, note the names as you will put  those in step 5 below.


Fields in Sandbox or Production
Using the same links above, click on the module in question, for example, here is LEADS in sandbox;

5 Copy this code into the function, put your Goolge API keys in the urls, then add your ZOHO module and field API names on  the update call.

data = getUrl(" https://maps.googleapis.com/maps/api/geocode/json?address=" + zip + "&key=MY_GOOGE_CLOUD_API_KEY");
result = data.getJSON("results");
geometry = result.toJSONList().get(0).getJSON("geometry").toJSONList();
location = geometry.get(0).getJSON("location");
lat = location.getJSON("lat");
long = location.getJSON("lng");
timezone = getUrl(" https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + long + "&timestamp=0900000000&key=MY_GOOGE_CLOUD_API_KEY").getJSON("timeZoneName");
update = zoho.crm.update("MY_LEADS_API_NAME",ToLong(leadid),{"MY_LEADS_FIELD_API_NAME":timezone});

6 Now trigger this with a workflow to update the record when added/edited etc...