Duplicate Phone Number

Today I came across an interesting post on SugarCRM Forum which says give an indication next to phone number if it is found to be repeated over various Contacts.

Steps are as below,

Step 1: Create a process_record logic hook in custom/modules/Contacts/logic_hooks.php
Add following code in it. If the file already exists, add following lines.

<?php
$hook_array['process_record'][] = Array(1, 'Check Dup', 'custom/modules/Contacts/checkDup.php','checkDupC', 'checkDupF'); 

Step 2: Lets add logic. Create a file checkDup.php under custom/modules/Contacts folder and add following code.

<?php
class checkDupC{
    function checkDupF($bean){
        $sContacts = $bean->db->query('SELECT contacts.id FROM contacts WHERE contacts.phone_work = "'.$bean->phone_work.'" AND contacts.id <> "'.$bean->id.'" AND contacts.phone_work IS NOT NULL', true);
        $bFound = false;
        while($aContacts = $bean->db->fetchByAssoc($sContacts)){
            if(!empty($aContacts['id']))
                $bFound = true;
        }
        
        if($bFound){
            $bean->phone_work = $bean->phone_work." ".SugarThemeRegistry::current()->getImage('no');
        }
    }
}

 Refresh the list view.

You should have next to the duplicated phone numbers.

Hope this helps and feels like missing piece is just found!

Feel free to drop your comments.

Your valuable feedback means a lot.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *