Move related record

Hi,

I have created a new contact->lead relationship and new contact->contact relationship

Therefore the below tables are created

contacts_contacts_1_c;

±--------------------------------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±--------------------------------±------------±-----±----±--------±------+
| id | varchar(36) | NO | PRI | NULL | |
| date_modified | datetime | YES | | NULL | |
| deleted | tinyint(1) | YES | | 0 | |
| contacts_contacts_1contacts_ida | varchar(36) | YES | MUL | NULL | |
| contacts_contacts_1contacts_idb | varchar(36) | YES | MUL | NULL | |
±--------------------------------±------------±-----±----±--------±------+

contacts_leads_1_c;

±-----------------------------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±-----------------------------±------------±-----±----±--------±------+
| id | varchar(36) | NO | PRI | NULL | |
| date_modified | datetime | YES | | NULL | |
| deleted | tinyint(1) | YES | | 0 | |
| contacts_leads_1contacts_ida | varchar(36) | YES | MUL | NULL | |
| contacts_leads_1leads_idb | varchar(36) | YES | MUL | NULL | |
±-----------------------------±------------±-----±----±--------±------+

I wanted to move this related record when Lead is converted to Contact.
I’ve created the below logic_hook

class lead_conv_mv {

    function lead_conv_mv_func(&$bean, $events, $arguments) {
            global $db;
            $query = "SELECT contacts_leads_1contacts_ida FROM contacts_leads_1_c WHERE contacts_leads_1leads_idb = '".$bean->id."' AND deleted=0";
            $GLOBALS['log']->debug($query);
            $result=$db->query($query);
            while ($row = $bean->db->fetchByAssoc($result)){
            $relate_con = $row['contacts_leads_1contacts_ida'];
            $query = "INSERT INTO contacts_contacts_1_c (deleted,contacts_contacts_1contacts_ida,contacts_contacts_1contacts_idb) VALUES ('0','".$bean->id."','".$relate_con."')";
            $GLOBALS['log']->debug($query);
            }
    }

}

However the “$bean->id” in INSERT statement is wrong.
I basically needed the new contact ID that is generated in order to map the related record.

Any pointers are appreciated.

And yes I’m using SuiteCRM Version 7.0.1
Sugar Version 6.5.16 (Build 1082)

Thanx in advance.

Hi Nigel,

What type of logic_hook are you using?

Thanks
Lewis