Entering the Opportunity Role on the Lead

I want to put an "Opportunity Role" field on the Leads module that when the Lead is converted places the Role value in the opportunities_contacts relationship. Has anyone done this before? If not, any suggestions on the best way to go about it?

Parents
  • I have not tried this and the code below is NOT tested, but, I would use an after_relationship_add logic hook.

    from Opportunities, when the Opportunity is related to a Lead:

    • fetch the Lead
    • find the contact_id on the Lead (this will be the Contact that the Lead was Converted to)
    • find the contact role that you set in the dropdown on the Lead
    • update the role:
      • $oppBean->contacts->add($contact_id, array('contact_role' => $contact_role));

    So your after_relationship_add logic hook in Opportunities will look something like:

    function updateContactRole ($bean,$event,$arguments){
        if($arguments['related_module'] == 'Leads'){
            $leadBean = BeanFactory::retrieveBean('Leads',  $arguments['related_id']);
            if(!empty($leadBean)){
                if(!empty($leadBean->contact_id) && !empty($leadBean->contact_role_c)){
                    $contact_role = $leadBean->contact_role_c; //get the contact role from your Lead
                    $contact_id = $leadBean->contact_id;  //get the contact_id
                    //set the contact role on the Opportunity Contact relationship
                    $bean->contacts->add($contact_id, array('contact_role' => $contact_role));
                }
            }
        }
    }    

     

Reply
  • I have not tried this and the code below is NOT tested, but, I would use an after_relationship_add logic hook.

    from Opportunities, when the Opportunity is related to a Lead:

    • fetch the Lead
    • find the contact_id on the Lead (this will be the Contact that the Lead was Converted to)
    • find the contact role that you set in the dropdown on the Lead
    • update the role:
      • $oppBean->contacts->add($contact_id, array('contact_role' => $contact_role));

    So your after_relationship_add logic hook in Opportunities will look something like:

    function updateContactRole ($bean,$event,$arguments){
        if($arguments['related_module'] == 'Leads'){
            $leadBean = BeanFactory::retrieveBean('Leads',  $arguments['related_id']);
            if(!empty($leadBean)){
                if(!empty($leadBean->contact_id) && !empty($leadBean->contact_role_c)){
                    $contact_role = $leadBean->contact_role_c; //get the contact role from your Lead
                    $contact_id = $leadBean->contact_id;  //get the contact_id
                    //set the contact role on the Opportunity Contact relationship
                    $bean->contacts->add($contact_id, array('contact_role' => $contact_role));
                }
            }
        }
    }    

     

Children
No Data