Look Up Zip/Postal and Populate Fields

Function: addressautoresolver.lookupAndParsePostalCode
Since Version: 1

Looks up a zip or postal code and parses the result to populate fields on the a record.

Syntax

addressautoresolver.lookupAndParsePostalCode (
	recType,
	recId,
	pCode,
	fields,
	conditions,
	distances
)

Arguments

  • recType
    type: string

    The Zoho CRM API name for the record type that will receive field updates (i.e., "Contacts", "Leads", etc).

  • recId
    type: bigint

    The ID of the destination record that will receive the field updates.

  • pCode
    type: string

    The zip or postal code that you want to resolve.  For US addresses, this is the five digit zip code.  US Zip+4 codes are not yet supported.

  • fields
    type: map

    Map of Zoho field API names to field names returned from the lookup.  Takes the form of Zoho_Field = Result_Field.  Required.

    Valid result field names are:

    • base_city: The resolved city name
    • base_state_province: The state or province spelled out
    • base_state_abbr: The state or province code (i.e., CA for California)
    • base_postal_zip: The postal or zip code
    • base_longitude: Longitude of the center of the zip or postal code
    • base_latitude: Latitude of the center of the zip or postal code
    • base_county: The county of the zip code (US Only)
    • country_name: The result country spelled out
    • country_code: The result country code (i.e., US for United States)
    • country_currency_code: The result currency code (i.e., CAD for Canadian Dollars)

    In addition to the standard fields, you can also use the results of the distances found to the distances value.  All distance results are returned in order of nearest to furthest, so distance #1 will be the closest.  To map the data returned in distances you reference the location number in the map: distance_[x]_[field_name].  Fields you can use are:

    • distance_[x]_miles: Miles to the location (rounded to the nearest integer)
    • distance_[x]_kilometers: Kilometers to the location (rounded to the nearest integer)
    • distance_[x]_[user_field]: Any user fields passed for the given index.

    If you provide a distance index (x) that is out of bounds then the highest index item will be returned.  For example, if you have 3 locations and ask for "distance_10_miles" the returned value will be from "distance_3_miles".

    User fields passed will always be returned with all spaces converted to underscores and all field names in lowercase.  I.e., "Sales Person Name" will return as "distance_[x]_sales_person_name".

    Deluge Map Example:

    fields = Map();
    fields.put("Mailing_City","base_city");
    fields.put("Mailing_State","base_state_province");
    fields.put("Closest_Office_Distance","distance_1_miles");
    fields.put("Closest_Office","distance_1_name");
    
  • conditions
    type: map

    The conditions in which the lookup will be performed or field updated.  Takes the form of Zoho_Field = Condition.  If null is passed as the map or an empty map is passed then no conditions will be applied and all fields in the fields map will be updated.

    Valid condition names are:

    • isempty: Perform lookup and populate field only if the field has no value.  If the field has a value then no field updates will be applied to any field
    • onlyifempty: Perform lookup and populate field only if the field has no value.  Applies only to this field, other fields will be processed normally
    • hasvalue: Perform lookup and populate field only if the field has a value.  If the field has no value then no field updates will be applied to any field
    • onlyifhasvalue: Perform lookup and populate field only if the field has a value.  Applies only to this field, other fields will be processed normally

    Deluge Map Example:

    conditions = Map();
    conditions.put("Mailing_City","onlyifempty");
    
  • distances
    type: map

    If you want to retrieve distances to the pCode's central location then you can create a map of locations to resolve.  If the value passed is null or an empty map then no distances will be calculated.

    The Deluge map may include three values:

    • max_distance (Optional): The maximum distance that any location can be, anything outside of this radius will not be returned.  Defaults to the entire globe.
      Type: int
    • max_count (Optional): Maximum number of the provided locations to return.  This is useful if you want to look up, say, 20 offices but only want the 3 closest  If you specify more locations than you are licensed for you will only get up to your license count.  Defaults to all.
      Type: int
    • locations (Required): List of all locations to compare with.  Each location must provide either GPS coordinates, named longitutde and latitude or a zip/postal code named zip_postal.  If both GPS coordinates and zip/postal code are provided, GPS will take priority since GPS is far more accurate.
      Type: list

    If any other fields are passed in addition to longitudelatitude or zip_postal then those fields will be returned as user defined fields in the result.  If you don't have enough distance licenses to resolve all locations passed then the first X locations in your list of locations will be used, where X represents the licenses you have.

    Deluge Map and List Example:

    offices = List();
    
    office1 = Map();
    office1.put("zip_postal", "90210");
    office1.put("Name", "Beverly Hills Office");
    office1.put("Sales_Person_Name", "Jill Evans");
    offices.add(office1);
    
    office2 = Map();
    office2.put("latitude", "39.696254");
    office2.put("longitude", "-105.034428");
    office2.put("Name", "Denver Office");
    office2.put("Sales_Person_Name", "William Johnston");
    offices.add(office2);
    
    office3 = Map();
    office3.put("zip_postal", "M2K 1W9");
    office3.put("Name", "Toronto Office");
    office3.put("Sales_Person_Name", "Evan Delrude");
    offices.add(office3);
    
    locations = Map();
    locations.put("max_distance", 25);
    locations.put("max_count", 3);
    locations.put("locations", offices);
    

Examples

© Eagle. All rights reserved.