AnsweredAssumed Answered

Transferring relationships on Lead Conversion

Question asked by Info Tech on Jul 27, 2016
Latest reply on Jul 28, 2016 by Info Tech

Hi there, I'm attempting to move all of the relationships of notes/emails and a custom module of mine called jn_jetnetaircraft across to the contact, and the point of lead conversion.


I've followed along with Angel Magana blog post at Angel's Blog: Logic Hooks: Lead History Transfer


I have the following lead transfer code, for which is under sugar 7.7.0

class DataTransfer {      function convertNotes($bean,$lead_id,$contact_id,$contact)     {         $bean->load_relationship('notes');          //Remove relationship         $notes = array();         foreach ($bean->notes->getBeans() as $note)         {             $note_id = $note->id;             $notes[] = $note_id;             $bean->notes->delete($lead_id, $note_id);         }          //Transfer relationship to Contact record                  $contact->load_relationship('notes');         foreach ($notes as $note)         {             $contact->notes->add($note);         }     }          function convertEmails($bean,$lead_id,$contact_id,$contact)     {         $bean->load_relationship('emails');          //Remove relationship         $items = array();         foreach ($bean->emails->getBeans() as $item)         {             $item_id = $item->id;             $items[] = $item_id;             $bean->emails->delete($lead_id, $item_id);         }                   $contact->load_relationship('emails');         foreach ($items as $item)         {             $contact->emails->add($item);         }     }          function convertJetnet($bean,$lead_id,$contact_id,$contact)     {         $bean->load_relationship('jn_jetnetaircraft_leads_1');         //Remove relationship         $items = array();         foreach ($bean->jn_jetnetaircraft_leads_1->getBeans() as $item)         {             $item_id = $item->id;             $items[] = $item_id;             $bean->jn_jetnetaircraft_leads_1->delete($lead_id, $item_id);         }                   $contact->load_relationship('jn_jetnetaircraft_contacts_1');         foreach ($items as $item)         {             $contact->jn_jetnetaircraft_contacts_1->add($item);         }         $GLOBALS['log']->fatal(print_r($contact, true));             }            function doDataTransfer($bean, $events, $arguments)     {         global $GLOBALS;                  $action  = $_REQUEST['action'];          if ($action == 'ConvertLead') //Must confirm it only triggers on conversion!!         {             $GLOBALS['log']->fatal('Debugging message - do data transfer');                     $lead_id  = $bean->id;             $contact_id = $bean->contact_id;             $contact = new Contact();             $contact->retrieve($contact_id);             convertNotes($bean,$lead_id,$contact_id,$contact);             convertEmails($bean,$lead_id,$contact_id,$contact);             convertJetnet($bean,$lead_id,$contact_id,$contact);                          //Save the bean eventually.             $bean->save();         }     } }

So this works for the notes and Emails ok.

However it will not work for the jetnet module.

I also don't get any logging to the sugarcrmlog with my fatal requests....


I've checked the name of the relationships in both studio and by checking ext/vardefs

They match up with what I have for leads and contacts.


Any help would be greatly appreciated!