Wednesday, August 7, 2013

Duplicate Finder

This is what i have find during surfing on internet,

Give an indication next to phone number if it is found to be repeated over various Contacts :

1.Create a process_record logic hook in custom/modules/Contacts/logic_hooks.php



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

2. Create a file checkDup.php in SugarCRM/custom/modules/Contacts/








<?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."&nbsp;".SugarThemeRegistry::current()->getImage('no');
}
}
}

Now, refresh the list view and you should have (X) mark after phone number.









Wednesday, June 26, 2013

Dependable Required Field




e.g.: 
       My Module Name : Desner
       Field                   : desnerStatus_c ( DropDown ) (Values :  nitin, blog, spot, nrsd)



Condition : if i select nrsd from desnerStatus_c dropdown want description required else remove validation.


Step1: Copy or make path like Sugarcrm/custom/modules/Desner/views/view.edit.php

Step2: copy below code in view.edit.php

<?php
require_once('include/MVC/View/views/view.edit.php');
class DesnerViewEdit extends ViewEdit {
    public function __construct() {
        parent::ViewEdit();
        $this->useForSubpanel = true; 
        $this->useModuleQuickCreateTemplate = true; 
    }
    function display() {
        global $mod_strings;
        $jsscript = <<<EOQ

                   <script>
                      
       $('#desnerStatus_c').change(function() {
            makerequired(); 
                       });
 function makerequired()
  {
        var status = $('#desnerStatus_c').val(); 
       if(status == 'nrsd'){                     addToValidate('EditView','description','varchar',true,'{$mod_strings['LBL_DESCRIPTION']}');                           $('#description_label').html('{$mod_strings['LBL_DESCRIPTION']}: <font color="red">*</font>'); 
                            }
       else{
          removeFromValidate('EditView','description');                       
                        $('#description_label').html('{$mod_strings['LBL_DESCRIPTION']}: '); 
                            }
         }
     makerequired(); 
    </script>
EOQ;
        parent::display();
        echo $jsscript;     
    }

}



Note:

  •         It is tested on SugarCRM 6.5 and above
  •         For another version that not supported JQuery add one line after <<<EOQ
         <script src="http://code.jquery.com/jquery-1.9.1.js"></script>




Step 3 : Any Query Please Make comment




                                                       



Ad