Auto-fill lead addresses

Help your sales team save time and reduce errors by automatically filling address information in lead records based on the entered zip code.

Addresses are essential in CRM throughout the entire customer lifecycle. From managing leads to finalizing sales orders, generating invoices, and closing deals, accurate address information is necessary at every stage. It also ensures that communication, product delivery, and service provision are all executed seamlessly and efficiently. One way to ensure address accuracy is to automatically suggest or complete the address based on the entered zip code, making it easier for salespeople to fill in the rest of the details. Auto-complete also helps standardize address formats, which is particularly beneficial for shipping and delivery purposes.

In Zoho CRM, the address auto-complete functionality is not available by default. However, you can use our low-code tools to add this capability to your application. You just need to write a custom function and connect it with a workflow rule to ensure error-free addresses. Read on to learn more.

Permissions and availability

  • Users must have a Google Cloud Billing project to create Google Maps API keys.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Generate an API key for the Google Maps API that will be used in the custom function. Learn more
  • Create a workflow rule for the Leads module that triggers every time you create or update a lead record. Learn more
  • Write a custom Deluge function that auto-fills the address fields such as city, state, and country in the lead records. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Create a Google Maps API key

The first step is to create your Google Maps API key, which will be used in the code snippet. Video Tutorial

  1. Go to the Google Maps Platform.
  2. Click the Get Started button and Google Cloud Platform home in the top left corner.
  3. Click Billing to ensure your billing details are up-to-date.
    Note: To generate a key, you must have a Google account with billing enabled.
  4. Click Google Cloud Platform home in the top left corner again.
  5. Hover over APIs & Services, then select Credentials.
  6. Select an existing project from the list if you prefer to use one. Otherwise, select Create a new project and enter a project name.
  7. Click Create credentials and select the API key from the drop-down menu.
    A popup will appear to display the new API key.
  8. Click the Copy to clipboard icon to copy the API key.
  9. Click the Close button in the popup.
    Your new API key will be listed on the Credentials page under API keys.
Create Google Maps API key

Create a workflow rule

The next step is to create a workflow rule with a custom function to auto-populate the address information.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Leads from the module dropdown list.
  3. Provide a name for the rule. For example: "Autofill address information".
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, choose Record Action, then select Create or Edit from the dropdown and click Next.
  6. In the Which leads would you like to apply the rule to? section, select All Leads and then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name for the function, as well as a description, if necessary.
  9. In the Deluge Script Editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Edit Arguments.
    3. Choose Leads - Lead Id, then name it leadId.
    4. Click the + icon to add more arguments.
    5. Choose Leads - Zip Code, name it zip, and click Save.
    6. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
data = getUrl("https://maps.googleapis.com/maps/api/geocode/json?address=" + zip + "&key=xxxxx");
info "data : " + data;
result = data.get("results");
mp = Map();
for each  rec in result
{
	recmap = rec.toMap();
	address_components = recmap.get("address_components").toJSONList();
	for each  ele in address_components
	{
		eleMap = ele.toMap();
		typeVal = eleMap.get("types");
		if(typeVal.contains("locality"))
		{
			City = eleMap.get("short_name");
			mp.put("City",City);
		}
		else if(typeVal.contains("administrative_area_level_1"))
		{
			State = eleMap.get("long_name");
			mp.put("State",State);
		}
		else if(typeVal.contains("country"))
		{
			Country = eleMap.get("long_name");
			mp.put("Country",Country);
		}
	}
}
updateResp = zoho.crm.updateRecord("Leads",leadId,mp);
info mp;
info updateResp;

Notes

  • Replace 'xxxxx' with the Google Maps API key generated in the above steps.
  • Make sure to use the accurate API names for their corresponding fields in the code snippet (e.g., State). Learn more
  • The script above is an example of how to automatically fill in address information in leads, including city, state, and country, based on the entered zip code. You can customize this code to auto-fill addresses in other modules, such as Contacts, by changing the module, field names, and other parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Go to Leads > +Create Lead.
  2. Enter the lead information, such as their first name, last name, street, and zip code.
  3. Click Save.
    The workflow rule will be triggered.
  4. Check whether the lead's address information, such as city, state, and country, is automatically populated without errors.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleLeads
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Google Maps PlatformWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!