logic hooks on EmailAddress relationships not working?

I need to trigger a process when an Email Address is added or removed from a Contact.

I was hoping to leverage the after_relationship_add/after_relationship_delete on Contacts:

  function EmailAddressChanged($bean, $event, $arguments){
    if($arguments['related_module'] == 'EmailAddresses'){
      $bean->pending_accounting_sync_c = 1;
      $bean->save();
    }
  }

but it is not triggering at all, is the relationship to EmailAddresses not treated like other relationships?

thanks,

FrancescaS

  • Hi Francesca Shiekh

    Unfortunately all crud events are implemented by direct sql queries, as per SugarEmailAddress.save (include/SugarEmailAddress/SugarEmailAddress.php:288).

    So the unique way to manage that is by stored procedure.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Turns out I was overthinking it.

    I can use the before save fetched row and the getAddressesForBean and diff the resulting email addresses to see if any were added/removed.

            $fetchedEmailAddresses = $bean->fetched_row['email'];
            $EmailAddresses = $bean->emailAddress->getAddressesForBean($bean, true);

    FrancescaS