Zoho FSM | Push Zoho FSM Contacts to Google Contacts

Push Zoho FSM Contacts to Google Contacts

Use case: Push (create/update) a Zoho FSM contact to Google Contacts. Changes made to the Name, Email, Mobile, Phone, or Service Address of the Zoho FSM Contact will reflect in the corresponding Google Contact.
 
Follow the steps below to implement this use case:
Step 1: Create a custom field
Step 2: Create a connection for Google Contacts
Step 3: Create a workflow rule

Step 1: Create a custom field 

Create a custom field Google Contact ID of type Single Line in the Contacts module. This field will be used to store the ID of the Google Contact created for the Zoho FSM Contact.
 
Drag and drop a new section and name it as Other Info.
 
 
To the Other Info section, drag and drop a Single Line field and name it as Google Contact ID.


Step 2: Create a connection for Google Contacts 

To create a connection for Google Contacts that can be used in Zoho FSM for invoking the Google Contacts APIs, do the following:
  1. Navigate to Setup > Developer Space > Connections and under Default Services, select Google Contacts.



  2. Click Create Connection.



  3. Perform the following and click Create And Connect:
    1. Connection Name: googlecontact
      The Connection Link Name will be populated automatically.
    2. Disable Use Credentials of Login User.
    3. For the Scopes, select https://www.google.com/m8/feeds/



  4. Click Connect.



  5. Click Connect.


In the custom function, where the Google Contacts APIs are used via the invokeURL tasks, use this Connection Link Name.


Step 3: Create a workflow rule

Create a workflow rule in Zoho FSM to automatically create a Contact record in Google Contacts from a Zoho FSM Contact. Changes made to the Name, Email, Mobile, Phone, or Service Address of the Zoho FSM Contact will reflect in the corresponding Google Contact.
  1. Go to Setup > Automation > Workflow Rules and click Create Workflow.
  2. Enter the following details, then click Next:
    1. Module: Contacts
    2. Rule Name: CreateUpdateGoogleContacts



  3. Select the rule trigger as Created or Edited and click Next. Ensure that Repeat this workflow whenever a Contact is edited is selected.



  4. Select the rule criteria as To all Contacts and click Next.



  5. Click +Action and select Function.



  6. Select Create your own Function and click Next.



  7. Enter the following and click Save and Associate:
    1. Function Name: createupdategooglecontact
    2. In the Deluge Editor, paste this script and replace the placeholders with actual values.



  8. Click Save.


Custom Function Script 

Below is the custom function script:
 

fullName = contact.get("Full_Name");
email = contact.get("Email");
phone = contact.get("Mobile");
mobile = contact.get("Phone");
address = contact.get("Service_Address");
ginput = Map();
ginput.put("names",{{"givenName":fullName}});
if(email != null)
{
 ginput.put("emailAddresses",{{"value":email}});
}
if(mobile != null)
{
 ginput.put("phoneNumbers",{{"value":mobile}});
}
if(phone != null)
{
 if(ginput.containKey("phoneNumbers"))
 {
  phonenumberList = ginput.get("phoneNumbers").toList();
  phonenumberList.add({"value":phone});
  ginput.put("phoneNumbers",phonenumberList);
 }
 else
 {
  ginput.put("phoneNumbers",{{"value":phone}});
 }
}
if(address != null)
{
 ginput.put("addresses",{{"city":address.get("City"),"country":address.get("Country"),"postalCode":address.get("Zip_Code"),"streetAddress":address.get("Street_1")}});
}
if(contact.get("Custom_Field_ID") != null)
{
 googleContactId = contact.get("Custom_Field_ID");
 personFields = {"personFields":"names,phoneNumbers"};
 getGcontactInfo = invokeurl
 [
  url :"https://people.googleapis.com/v1/" + googleContactId
  type :GET
  parameters:personFields
  headers:Map()
  connection:"Connection_Name"
 ];
 if(getGcontactInfo != null && getGcontactInfo.get("etag") != null)
 {
  etagid = getGcontactInfo.get("etag");
  ginput.put("etag",etagid);
  gUpdateResp = invokeurl
  [
   url :"https://people.googleapis.com/v1/" + googleContactId + ":updateContact?updatePersonFields=names,addresses,phoneNumbers,emailAddresses"
   type :PATCH
   parameters:ginput.toString()
   headers:Map()
   connection:"Connection_Name"
  ];
  info gUpdateResp;
 }
 else
 {
  gcontactresp = invokeurl
  [
   type :POST
   parameters:ginput.toString()
   headers:Map()
   connection:"Connection_Name"
  ];
  if(gcontactresp != null && gcontactresp.get("resourceName") != null)
  {
   googleResourceName = gcontactresp.get("resourceName");
   updatedResp = zoho.fsm.updateRecord("Contacts",contact.get("id"),{"Custom_Field_ID":googleResourceName});
   info updatedResp;
  }
 }
}
else
{
 gcontactresp = invokeurl
 [
  type :POST
  parameters:ginput.toString()
  headers:Map()
  connection:"Connection_Name"
 ];
 if(gcontactresp != null && gcontactresp.get("resourceName") != null)
 {
  googleResourceName = gcontactresp.get("resourceName");
  updatedResp = zoho.fsm.updateRecord("Contacts",contact.get("id"),{"Custom_Field_ID":googleResourceName});
  info updatedResp;
 }
}

Replace Custom_Field_ID with the Api name of the custom field.



Replace connection_name with the Connection Link Name.
 

Testing the use case

Create a Zoho FSM Contact. A corresponding contact will be added in Google Contacts. The Google Contact ID field in the Zoho FSM Contact record will be populated with the ID of the Google Contact created (refer to the screenshot below).
 

 
Any changes made to the Name, Email, Mobile, Phone, or Service Address of the Zoho FSM Contact will reflect in the corresponding Google Contact.