Mass convert Targets to Leads

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

Steps are as below,

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.

<?php 
$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.

<?php
$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.

<?php 
$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.

<?php 
class convertIntoLeadsC {
    function convertIntoLeadsF($bean, $event, $args) {
        if (isset($bean->convert_prospect) && $bean->convert_prospect != $bean->fetched_row['convert_prospect'] && empty($bean->lead_id)) {
            $oLead = new Lead();
            foreach ($oLead->field_defs as $keyField => $aFieldName) {
                $oLead->$keyField = $bean->$keyField;
            }
            $oLead->id = '';
            $oLead->save(true);
            $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!!

Note :

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

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 *