Robert Sinclair
Robert Sinclair

Reputation: 5426

Convert lead into a contact using a logic hook

I looked in the dev guide and online but can't seem to find any code examples. I'm just trying to convert a lead into a contact.

For example I have a lead with ID: 7, what I'm trying to do is possibly modify a bean property to convert that lead into a contact (not sure if this approach is correct). Something like

$bean->convert("Contact");

$bean->save();

Thank you for your advice

Upvotes: 1

Views: 247

Answers (1)

Ashish Dwivedi
Ashish Dwivedi

Reputation: 109

In sugar/suite, conversion is a process which is copying a bean from one module to another module e.g. lead into contact.

I have been using this function to make it happen.

function outright_copy_bean($old_bean){
    $new_bean = new $old_bean->object_name;
            foreach($new_bean->field_defs as $key => $value){
                if(in_array($key, array("id", "date_entered"))){
                    continue;
                }
                if($value["type"] == "link"){
                    continue;
                }
                $new_bean->$key = $old_bean->$key;
            }
    $new_id = $new_bean->save();
    return $new_id
 }

Upvotes: 1

Related Questions