Hello Dear Sugar Community!
I want to put all Email-addresses in the module contacts to "opt_out" if the checkbox "inaktiv_c" is checked.
I use a hook, but unfortunately it doesn't work. The hook itself gets triggered, i tried it with error_log. Here is my Code:
<?php
class Email_Hook
{
function before_save_method($bean, $event, $arguments)
{
if ($bean->inaktiv_c) {
if (!$bean->load_relationship('email_addresses'))
return;
$relatedBeans = $bean->email_addresses->getBeans();
foreach ($relatedBeans as $relatedBean) {
$relatedBean->opt_out = 1;
$relatedBean->save();
}
}
}
}
?>
Can you tell me what i have done wrong?
Thank You!