AnsweredAssumed Answered

duplicate check not enforcing "and"

Question asked by Francesca Shiekh on Oct 19, 2017
Latest reply on Oct 19, 2017 by Francesca Shiekh

I have a custom module AddressLocations with the following duplicate check. Notice the AND clause.

<?php
// duplicate check
$dictionary['addlo_Address_Locations']['duplicate_check']
  'enabled' => true,
  'FilterDuplicateCheck' => array(
     'filter_template' => array(
       array(
         '$and' => array(
            array('address_line_1_c' => array('$equals' => '$address_line_1_c')),
            array('address_country' => array('$equals' => '$address_country')),
            array('address_city' => array('$equals' => '$address_city')),
            array('addlo_addr2856ccounts_ida' => array('$equals' => '$addlo_addr2856ccounts_ida')),
         ),
       ),
     ),
     'ranking_fields' => array(
        array(
          'in_field_name' => 'addlo_addr2856ccounts_ida',
          'dupe_field_name' => 'addlo_addr2856ccounts_ida',
        ) ,
        array(
          'in_field_name' => 'address_line_1_c',
          'dupe_field_name' => 'address_line_1_c'
        ),
        array(
          'in_field_name' => 'address_country',
          'dupe_field_name' => 'address_country',
        ),
        array(
          'in_field_name' => 'address_city',
          'dupe_field_name' => 'address_city',
        ),
     ),
  ),
);

 

During Lead Conversion, I include the AddressLocations module, copying the fields from the Lead address fields to AddressLocations:

custom/modules/Leads/clients/base/layouts/convert-main/convert-main.php

            4 =>
            array (
              'copyData' => true,
              'required' => false,
              'moduleName' => 'Address Locations',
              'module' => 'addlo_Address_Locations',
              'duplicateCheckOnStart' => true,
              'fieldMapping' =>
              array (
                'business_region' => 'business_region_c',
                'affiliation' => 'affiliation_c',
                'address_postalcode' => 'address_postalcode_c',
                'address_line_1_c' => 'address_line_1_c',
                'address_country' => 'address_country_c',
                'address_city' => 'address_city_c',
              ),
              'dependentModules' =>
              array (
                'Accounts' =>
                array (
                  'fieldMapping' =>
                  array (
                    'addlo_addr2856ccounts_ida' => 'id',
                    'addlo_addre_accounts_name' => 'name',
                  ),
                ),
                'Contacts' =>
                array (
                  'fieldMapping' =>
                  array (
                    'addlo_addrd2e2ontacts_idb' => 'id',
                  ),
                ),
              ),
            ),

 

But not all address fields are required in web forms to generate a Lead. If the Lead on a web form filled in only a Country (e.g. US) the duplicate check for AddressLocations on Lead Conversions will return ALL addresses in the US. The resulting query is so bad that it will do a full table scan (we have 1.4M addresses). Which is not acceptable.

 

The query does not include all the fields included in the filter definition and the where clause will look like:

(addlo_address_locations.id != 'dd8b6c4e-b4d9-11e7-b46a-001a4a160206' 
AND (addlo_address_locations.address_country = 'US'))  

 

Since the filter condition is an AND, should it not include ALL parameters in the query? How do I stop the duplicate check from running if any of the parameters are missing?

Additionally, how do I stop the duplicate check from running BEFORE the Account is chosen?

 

Thanks,
FrancescaS

Outcomes