$bean->emailAddress->addAddress is not working, and $sea->addAddress REMOVES all other addresses

I am writing an API to change an email address on a contact.
I don't want to remove the old address, just add the new one as primary on the Contact bean.

I used the documented addAddress ( support.sugarcrm.com/.../ )

$contactBean->emailAddress->addAddress($new_email_address, true);
$contactBean->save();

But this won't even add the new address to Contact at all. There are no errors in the logs, I verified that the contactBean is a valid Bean, and that the $new_email_address is a valid address. I checked the parameters for the addAddress function and I verified that the function is being called.

What's worse

$sea = new SugarEmailAddress();
      $sea->addAddress($email_address,true);
      //do some checks...
      //add the email address to the Contact $bean
      $sea->save($bean->id, 'Contacts');

Adds the new address but DELETES all the others!

Has something changed in v11.0.1 (on site Professional) that I'm not aware of?

Thank you,
Francesca

Parents Reply
  • You didn't miss something because I can't find it either. I just did some testing myself and simply following the documentation would indeed lead to nowhere. The code that seems to work, and doesn't break anything, is as follows: (for adding addresses). But  removing doesn't seem to be working :( 

    // load the bean we want to update.
    $c = BeanFactory::retrieveBean('Contacts','f8c35990-453b-11eb-8f2d-34363bc92236');
    
    // add sample email adress to this bean
    $c->emailAddress->addAddress('address@sugar.crm');
    // save the email relationship
    $c->emailAddress->save($c->id, $c->module_dir);
    
    

Children