contacts duplicate check

Hi. I'm trying to modify the duplicate check filter for Contacts module.

I'm using the instructions at https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Architecture/Duplicate_Check/

and have added the code below to the location ./custom/Extension/modules/Contacts/Ext/Vardefs/duplicate_check_email_v7_twitter.php

The example removed the 'shipping_address_city' field, I have tried to use the same theory to add the 'twitter' field to test with but as far as I can tell it has made no difference.  

Can any of you see what the issue is please?

<?php

$dictionary['Contact']['duplicate_check']['FilterDuplicateCheck'] = array(
    'filter_template' => array(
        array(
            '$and' => array(
                array('twitter' => array('$starts' => '$twitter')),
                array('first_name' => array('$starts' => '$first_name')),
                array('last_name' => array('$starts' => '$last_name')),
                array('accounts.id' => array('$equals' => '$account_id')),
                array('dnb_principal_id' => array('$equals' => '$dnb_principal_id')),
            ),
        ),
    ),
    'ranking_fields' => array(
        array(
            'in_field_name' => 'twitter',
            'dupe_field_name' => 'twitter',
        ),
        array(
            'in_field_name' => 'account_id',
            'dupe_field_name' => 'account_id',
        ),
        array(
            'in_field_name' => 'last_name',
            'dupe_field_name' => 'last_name',
        ),
        array(
            'in_field_name' => 'first_name',
            'dupe_field_name' => 'first_name',
        ),

    ),
);

Also, would the updated duplicate check happen at the point of entry like it currently does if it matches a name, or is this for the 'Find Duplicates' you can run when in a record?

Thanks
James

  • The items you updated will check for duplicates when you save a new Contact record.

    According to your rules, you have an AND which means all of the criteria must be matched.

    if you review cache/modules/Contacts/Contactvardefs.PHP you should see your new definition in place of the original definition.

  • Thank you for responding and clarifying Jeff. 

    If you don't mind, have I got the following correct? Just so I can see a change working and understand it, I've tried to set it so the twitter field is one possible check, and the rest of the fields mentioned are another. Is the nesting correct, I'm trying to understand how the OR's and AND's ?  Starting the array with OR has thrown me.

    Thanks

    James

    <?php
    
    $dictionary['Contact']['duplicate_check']['FilterDuplicateCheck'] = array(
        'filter_template' => array(
            array(
                '$or' => array(
                    array('twitter' => array('$starts' => '$twitter')),
    
            array(
                '$and' => array(
                    array('first_name' => array('$starts' => '$first_name')),
                    array('last_name' => array('$starts' => '$last_name')),
                    array('accounts.id' => array('$equals' => '$account_id')),
                    array('dnb_principal_id' => array('$equals' => '$dnb_principal_id')),
                     ),
                  ),
                ),
            ),
        ),
        'ranking_fields' => array(
            array(
                'in_field_name' => 'twitter',
                'dupe_field_name' => 'twitter',
            ),
            array(
                'in_field_name' => 'account_id',
                'dupe_field_name' => 'account_id',
            ),
            array(
                'in_field_name' => 'last_name',
                'dupe_field_name' => 'last_name',
            ),
            array(
                'in_field_name' => 'first_name',
                'dupe_field_name' => 'first_name',
            ),
    
        ),
    );
     

  • Take a look at the Leads' vardefs. You will see, pretty much, exactly what you want to achieve.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Thank you André. 

    If I understand its behaviour, the Lead's vardef filter_template array seems to essentially hold an $and array which has two equally nested $or arrays that hold the fields to check, so either the first $or or second $or would be used depending on which fields are filled in, if all are filed in then the order of the ranking_fields array comes into play. Is that correct?

    Thanks

    James

  • Yes, this is correct

    André Lopes
    Lampada Global
    Skype: andre.lampada