0 Comments | 0 Shares | Urdhva Tech

Another interesting question on SugarCRM Forum attracted me to implement the request and here I go and write the solution for it.

Goal: Mass convert Targets to Leads.

Step 1: Create a flag field which allows you to mass convert Targets.

Create a file under custom/Extension/modules/Prospects/Ext/Vardefs/<any_name>.php and write following code in it.

$dictionary['Prospect']['fields']['convert_prospect'] = array('name' => 'convert_prospect',
    'vname' => 'LBL_CONVERT_PROSPECT',
    'type' => 'bool',
    'default' => '0',
    'massupdate' => true,

Create a file under custom/Extension/modules/Prospects/Ext/Language/en_us.<any_name>.php and write following code.

$mod_strings['LBL_CONVERT_PROSPECT'] => 'Convert Leads';

Then do Quick Repair and Rebuild which will give you a query to add a new field in prospects table.

Step 2: Create a before_save logic hook in Prospects module.

Create a file logic_hooks.php under custom/modules/Prospects if doesn't exist, or else add following code in it.

$hook_array['before_save'][] = Array(1, 'Mass Convert Prospects into Leads', 'custom/modules/Prospects/convertIntoLeads.php','convertIntoLeadsC', 'convertIntoLeadsF');

Step 3: Lets add logic behind.

Create a file convertIntoLeads.php under custom/modules/Prospects and add following code which copies the values from Prospect and creates a new lead.

class convertIntoLeadsC {
    function convertIntoLeadsF($bean, $event, $args) {
        if (isset($bean->convert_prospect) && $bean->convert_prospect != $bean->fetched_row['convert_prospect'] && empty($bean-&gt;lead_id)) {
            $oLead = new Lead();
            foreach ($oLead->field_defs as $keyField => $aFieldName) {
                $oLead->$keyField = $bean->$keyField;
            $oLead->id = '';
            $bean->lead_id = $oLead->id;

Now go to List View of Prospects and select the records you want to convert into Leads and mass update them by selecting Convert to Leads "Yes".

That's all! All selected Prospects are now converted into Leads!!

Mission accomplished!!

P.S. This feature will allow all users to convert Targets into Leads.

Feel free to leave your comments. 
Download attachments:
  • No Comments Found.
Post your comment