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?
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?
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:
$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));
}
}
}
}
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:
$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));
}
}
}
}