AnsweredAssumed Answered

set email opt_in when creating contact bean

Question asked by john Fieldsend on Mar 7, 2020
Latest reply on Mar 10, 2020 by Francesca Shiekh

Can anyone help with how you set a contacts primary email and set opt_out to 1 when a new contact bean is crated

 

        $contactbean                            = BeanFactory::newBean("Contacts");
        $contactbean->first_name                = $args['FirstName'];
        $contactbean->last_name                 = $args['LastName'];
        // $contactbean->email1                    = $args['Email'];
        $contactbean->portaluser_c              = $args['Email'];
        $contactbean->primary_address_country   = $args['MailingCountry'];
        $contactbean->primary_address_state     = $args['MailingState'];
        $contactbean->agreed_to_pp_c            = $args['Privacy_Policy'];
        $contactbean->save();

I read that i shouldn't be using email1 any more and instead use the email array

 

have tried 

 

        $contactbean->emailAddress->addAddress($args['Email']);
        //function addAddress($addr, $primary=false, $replyTo=false, $invalid=false, $optOut=false, $email_id = null, $validate = true)

        $bean = BeanFactory::newBean('EmailAddresses');
        $bean->getBeansByEmailAddress($args['Email']);
        $bean->emailAddress->addAddress($args['Email'], true, false, true, true);

 

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.0/Architecture/Email_Addresses/#Creat… 

 

this page says to pass it as a json object

Outcomes