In SugarCRM a Lead Conversion will not handle data from a custom module. Converting a lead that has data associated to it in a custom module will cause the data to be lost.

In my personal opinion this should be done automatically as long as you add this module on to the Lead Conversion screen. Unfortunately for now Sugar considers this as a feature request for a future version of SugarCRM.

Thankfully, there is a workaround solution that we can implement in code. This approach is upgrade safe so it can also be installed on a Sugar OnDemand environment.

In this example I have a custom module called Criteria which is 1-M with the Lead module. The Criteria module is used to identify the qualification of a particular lead. Once all the criteria have been met, a lead will be converted to an Account, Contact and in this case also an Opportunity. However out of the box, the data from the Criteria module would not transfer over.

Here is how we do it…..

First let’s create a manifest for the install-able package and we will use Module Loader to install this package.

MANIFEST.PHP


<?php 
$manifest = array(
 array('CE','PRO','CORP','ENT','ULT'),
	'acceptable_sugar_versions' => array(
	'exact_matches' =>
		array(
				0 => '7.5.2.2',
		)
	),

	'author' => 'Xtivia - Doddy Amijaya',
	'description' => 'Install Criteria logic hook',
	'icon' => '',
	'is_uninstallable' => true,
	'name' => 'Criteria Logic Hook',
	'published_date' => '2015-06-30 2015 20:45:04',
	'type' => 'module',
	'version' => '1.0',
 );

$installdefs = array(
	'id' => 'package_201506301159',
		'copy' => array(
				0 => array(
					'from' => '/Files/custom/modules/Leads/criteria_hook.php',
					'to' => 'custom/modules/Leads/criteria_hook.php',
				),
			),

	'logic_hooks' => array(
				array(
				'module' => 'Leads',
				'hook' => 'before_save',
				'order' => 99,
				'description' => 'Criteria Logic Hook',
				'file' => 'custom/modules/Leads/criteria_hook.php',
				'class' => 'Criteria',
				'function' => 'onLeadSave',
				),
			),
);

?>

The manifest and the installable logic hooks are done, now we create the code for the logic hook.

CRITERIA_HOOK.PHP


<?php
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    
    class Criteria
    {
       function onLeadSave($bean, $event, $arguments)
       {
	   get_linked_beans('criteria_leads','Crit_Criteria');
		 $lead_id = $bean->id;
		 $contactid = $bean->contact_id;
		 $opportunityid = $bean->opportunity_id;
		 $accountid = $bean->account_id;
		 
                 $criteriAarray = array();
		 foreach($allcriteria as $criteria)
		 {
		    $criteriAarray[] = $criteria->id;
		 }
		
		if($bean->converted == 1)
		{
		   if($contactid)
			{
			   $contact = new Contact();
			   $contact->retrieve($contactid);
			   $contact->load_relationship('criteria_contacts');
			   
			   foreach($criteriAarray as $c)
			   {		
				  $contact ->criteria_contacts->add($q);
			   }
			}

			if($accountid)
			{
			   $account = new Account();
			   $account->retrieve($accountid);
			   $account->load_relationship('criteria_accounts');

			   foreach($criteriAarray as $c)
			   {
				  $account ->criteria_accounts->add($q);
			   }
			}
			
			if($opportunityid)
			{
			   $opp = new Opportunity();
			   $opp->retrieve($opportunityid);
			   $opp->load_relationship('criteria_opportunities');

			   foreach($criteriAarray as $c)
			   {
				  $opp ->criteria_opportunities->add($q);
			   }
			}
		}
	}
}
?>

When this is done, we can zip up the two files into a zip file and install it using the module loader.

Hope this saves you some time! If you have any questions, please call the XTVIA CRM support line at 1-877-777-9779.

Share This