08
February

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.

<?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-&gt;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!!

Mission accomplished!!

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


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