Lead Campaign Data

I feel I must be doing something wrong here.

When a Lead is created after filling out a Form it often will have Campaign Log data.

I reported a problem to Support that when the Lead is converted, the Campaign Log data does not follow to the new Contact.

I was told this is a known defect and given a link to the bug. Notice below, this was reported almost 5 years ago!

So, assuming this is never going to be fixed, does anyone have any suggestions of how to do this better?

What the Lead has done until conversion is important, losing it (without having to view the Lead and Contact both to get the data) seems crazy.

Where am I going wrong?

Parents
  • As a workaround you could write a tiny logic_hook for Leads after_save which corrects the campaign_logs after a lead conversion. I attached a module loader package with such a tiny logic_hook, to show how it works.

    The main code of the hook:

    		if($event=="after_save"){
    			if (($arguments['isUpdate'] == 1)
    			&&  (!empty($arguments['dataChanges']) )	
    			&&  (!empty($arguments['dataChanges']['converted']) && 
    			     ($arguments['dataChanges']['converted']['before']==0) && 	
    			     ($arguments['dataChanges']['converted']['after']==1)) 	
    			&&  (!empty($arguments['dataChanges']['status']) && 
    			     ($arguments['dataChanges']['status']['before']!="Converted") && 	
    			     ($arguments['dataChanges']['status']['after']=="Converted")) 	
    			&&  (!empty($arguments['dataChanges']['contact_id']) && 
    			     ($arguments['dataChanges']['contact_id']['after']!="Converted")) 
    			) {
    				$LeadId = $bean->id;
    				$ContactId = $arguments['dataChanges']['contact_id']['after'];
    				$db = \DBManagerFactory::getInstance();
    				$query = "UPDATE campaign_log ".
    				         "SET target_type='Contacts',".
    						 "    target_id=".$db->quoted($ContactId)." ".
    						 "WHERE target_type='Leads' ".
    						 "AND   target_id=".$db->quoted($LeadId);
    				$results = $db->query($query);
    			}
    	    }
     

    The module loader package:

    2045.MoveCampaignlog.zip

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

Reply
  • As a workaround you could write a tiny logic_hook for Leads after_save which corrects the campaign_logs after a lead conversion. I attached a module loader package with such a tiny logic_hook, to show how it works.

    The main code of the hook:

    		if($event=="after_save"){
    			if (($arguments['isUpdate'] == 1)
    			&&  (!empty($arguments['dataChanges']) )	
    			&&  (!empty($arguments['dataChanges']['converted']) && 
    			     ($arguments['dataChanges']['converted']['before']==0) && 	
    			     ($arguments['dataChanges']['converted']['after']==1)) 	
    			&&  (!empty($arguments['dataChanges']['status']) && 
    			     ($arguments['dataChanges']['status']['before']!="Converted") && 	
    			     ($arguments['dataChanges']['status']['after']=="Converted")) 	
    			&&  (!empty($arguments['dataChanges']['contact_id']) && 
    			     ($arguments['dataChanges']['contact_id']['after']!="Converted")) 
    			) {
    				$LeadId = $bean->id;
    				$ContactId = $arguments['dataChanges']['contact_id']['after'];
    				$db = \DBManagerFactory::getInstance();
    				$query = "UPDATE campaign_log ".
    				         "SET target_type='Contacts',".
    						 "    target_id=".$db->quoted($ContactId)." ".
    						 "WHERE target_type='Leads' ".
    						 "AND   target_id=".$db->quoted($LeadId);
    				$results = $db->query($query);
    			}
    	    }
     

    The module loader package:

    2045.MoveCampaignlog.zip

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

Children