Converting lead to contact -> how to move event information

Hello all,

is it possible to move/copy event information (status, attendance info, etc) from lead to contact (converted from that lead)? There are ‘Lead Conversion Options’ in settings, but I assume that those options are only for activities (calls, notes, etc), not for event module data.

After conversion (lead -> contact) it would be nice to see which events that person has participated to.

Hey

I’ve done some research in the past and it looks like you would need to write something custom.

Below is the code I used, which creates a new “contact” and copies over the info in terms of actual fields, but doesn’t do anything in terms of relationships.

One thing I would recommend is to spend sometime to think through the need of maintaining leads AND contacts, in my experience just having leads and using the field “converted=1” to indicate that it’s now a customer was the best way to proceed.

Here’s the code you would need to adapt to your needs (pls disregard the custom write_to_log() function)

    $lead_bean = BeanFactory::getBean('Leads', $arguments['lead_id']);

    $contact_bean = BeanFactory::newBean('Contacts');

    // Copy all the fields from lead bean to contact bean
    foreach ($lead_bean->field_defs as $key => $value) {

        // Do not copy the "id" and "date entered". The contact will have it's own unique values
        if (in_array($key, array("id", "date_entered"))) {
            continue;
        }

        // skip empty/unwanted values
        if ($value["type"] == "link" OR empty($lead_bean->$key) OR $lead_bean->$key == "") {
            continue;
        }

        // If the contact bean has that property also than copy it over from the lead bean
        if (property_exists($contact_bean, $key)) {

            // If the value is not an array
            if(!is_array($lead_bean->$key)) {
                write_to_log(array(), "Yes the $key is found in the contact. Assigning val:".$lead_bean->$key." to contact bean");
            }

            // Write the value to contact bean (even if value is an array, we do this just in case)
            $contact_bean->$key = $lead_bean->$key;

        } else {

            write_to_log(array(), "No $key is not in it");

        }

    }


    $contact_bean->save();

    write_to_log(array(), "Newly created contact ID is ".$contact_bean->id);