Friday, 8 February 2013

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.

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. 

7 comments:

  1. Nice. For something like this, you could even set that checkbox field as a source=>non-db to make it a faux field, since you don't need to save the data anyway.

    This could also be applied to Lead -> Contact/Account.

    ReplyDelete
    Replies
    1. Hello Matthew,

      Thanks for your comment. But we created that field in db to determine if the Prospect is already converted into Prospect or not.

      Delete
  2. I Agree with the last post from Urdhva. I prefer the approach of use a status dropdown menu in Prospects, to assign "Converted" status, and even assigning the lead to an admin user, so that the normal users could not edit the Prospect again, and moving the activities from prospect to lead, using this post: http://forums.sugarcrm.com/search.php?searchid=1115588

    ReplyDelete
    Replies
    1. Hello Daniel,

      Thank you for your comment, appreciate it! The link you posted here doesnt work. It would be great if you post the correct one please..

      Delete
  3. This is nice. Could you please also explain how do I mass convert Targets directly into Contacts?

    ReplyDelete
  4. hi,

    when you convert a target to a lead does it copy over the history and activities to the “new” lead? for some reason i can’t get the history and activity information to copy over.

    thanks,

    gerard

    ReplyDelete
    Replies
    1. Hello Gerard,

      I dont think you can copy over history while converting Target into Lead. But there exists a functionality to copy over history while converting Lead into Contact. (File - modules/Leads/views/view.convertlead.php)

      Hope this helps.

      Delete

Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My Photo
SugarCRM Consultants Contact us at contact@urdhva-tech.com Skype : urdhvatech

Search This Blog

Loading...

Stay connected Socially

     

Total Pageviews

Popular Posts