$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
  • I have not been able to get that to work either. All the addAddress does is add it to the array of Email Addresses for the record, but it never gets saved to the database.

    I ended up with the following which is not pretty, but works:

    $emailParams = array(
        'email' => $sugarObject->emailAddress->addresses,
    );
    $emailParams['email'][] = array(
        'email_address' => $remoteObject->$remoteFieldName,
        'primary_address' => (count($emailParams['email']) == 0 ? 1 : 0),
        'opt_out' => !empty($GLOBALS['sugar_config']['new_email_addresses_opted_out']),
    );
    
    $sugarFieldEmail = new SugarFieldEmail("email");
    $sugarFieldEmail->apiSave($sugarObject, $emailParams, "email", $sugarFieldDefs['email']);
    

Reply
  • I have not been able to get that to work either. All the addAddress does is add it to the array of Email Addresses for the record, but it never gets saved to the database.

    I ended up with the following which is not pretty, but works:

    $emailParams = array(
        'email' => $sugarObject->emailAddress->addresses,
    );
    $emailParams['email'][] = array(
        'email_address' => $remoteObject->$remoteFieldName,
        'primary_address' => (count($emailParams['email']) == 0 ? 1 : 0),
        'opt_out' => !empty($GLOBALS['sugar_config']['new_email_addresses_opted_out']),
    );
    
    $sugarFieldEmail = new SugarFieldEmail("email");
    $sugarFieldEmail->apiSave($sugarObject, $emailParams, "email", $sugarFieldDefs['email']);
    

Children