I'm need check email address exist for other lead in before_save, but this $bean->email not work.
How get email address of new lead in before_save?
I'm need check email address exist for other lead in before_save, but this $bean->email not work.
How get email address of new lead in before_save?
Hi Rodolfo,
For the primary email address, you can use $bean->email1. I hope that helps!
-Alan
that is sequential ?
$bean->email1, $bean->email2, $bean->email3, $bean->email4, ....
I'm use this code
public function checkEmail($db, $obj){ | |||||
$retorno = ""; | |||||
$id_email = ""; | |||||
$res = array(); | |||||
//pega emails desse lead | |||||
$query = "SELECT ea.id, ea.email_address FROM email_addresses ea "; | |||||
$query.= "INNER JOIN email_addr_bean_rel eabr ON eabr.email_address_id = ea.id AND eabr.bean_module = 'Leads' AND eabr.deleted = 0 "; | |||||
$query.= "WHERE ea.deleted = 0 AND eabr.bean_id = '$obj->id' "; | |||||
$results = $db->query($query, true); | |||||
//$row = $db->fetchByAssoc($results); | |||||
$array_mail = array(); | |||||
do { | |||||
//$email.= $row['email_address']." - "; | |||||
$array_mail[$row['id']] = $row['email_address']; | |||||
}while($row = $db->fetchByAssoc($results)); | |||||
//verifica se email existe para outro lead | |||||
foreach ($array_mail as $key => $email) { | |||||
$query = "SELECT ea.id, ea.email_address FROM email_addresses ea "; | |||||
$query.= "INNER JOIN email_addr_bean_rel eabr ON eabr.email_address_id = ea.id AND eabr.bean_module = 'Leads' AND eabr.deleted = 0 "; | |||||
$query.= "WHERE ea.deleted = 0 AND eabr.email_address_id = '$key' AND eabr.bean_id <> '$obj->id' AND eabr.deleted = 0 "; | |||||
$results = $db->query($query, true); | |||||
$row = $db->fetchByAssoc($results); | |||||
$num_rows = $results->num_rows; | |||||
if($num_rows > 0){ | |||||
$retorno.= $row['email_address'].", "; | |||||
$id_email.= $row['id'].","; | |||||
$num_rows = 0; | |||||
} | |||||
} |
$res['id'] = $id_email; | |||
$res['mail'] = $retorno; |
if(empty($retorno)){ | |||
return ""; | |||
} | |||
else{ | |||
return $res; | |||
} | |||
} |