LogicHook deletes email address

I have created a LogicHook (after save) that updates the billing address of an Account to the primary address of a Contact.
I puzzled why the Contact email address is deleted when the billing address of the Account changes. Primary address is correctly updated.
Strangely enough this happens when I use the EditView page. When I use the inline edit it doesn’t happen.
What’s wrong here?

<?php // custom/modules/Accounts/AccountLogicHook.php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class AccountLogicHook { function updateRelatedContacts(&$bean, $event, $arguments) { // Update Related Contacts that have a 1-to-many relationship from the Account $billing_address_street = $bean->billing_address_street; $billing_address_postalcode = $bean->billing_address_postalcode; $billing_address_city = $bean->billing_address_city; $billing_address_country = $bean->billing_address_country; $phone_office = $bean->phone_office; if(!empty($billing_address_street)) { // Find the Related Contacts require_once('modules/Contacts/Contact.php'); $contacts = $bean->get_linked_beans('contacts', 'Contact'); foreach ($contacts as $contact) { $contact->primary_address_street = $billing_address_street; $contact->primary_address_postalcode = $billing_address_postalcode; $contact->primary_address_city = $billing_address_city; $contact->primary_address_country = $billing_address_country; $contact->save(FALSE); } } if(!empty($phone_office)) { // Find the Related Contacts require_once('modules/Contacts/Contact.php'); $contacts = $bean->get_linked_beans('contacts', 'Contact'); foreach ($contacts as $contact) { $contact->phone_work = $phone_office; $contact->save(FALSE); } } } // end of updateRelatedContacts } ?>

Hi

when you post code here on the forums, make sure you wrap it in the forums’ “code” tags, otherwise brackets get removed and it gets very confusing…

I don’t know the exact answer to your question, I only know Email is a special kind of field, because of the way you can have several emails in one contact. So it’s a one to many relationship, without being a full-blown module.

Have you tried inspecting the field called “–>email1”, and possibly reassigning that value inside the hook?