Why is the email1 field empty when retrieving a user using retrieve_by_string_fields()?

Why does $user->retrieve_by_string_fields() is finding the user but with an empty email1 field?

i need to retrieve a user and then update it using save().
i noticed that each time i do that, the email1 is deleted.
so i checked the user email1 field and noticed that after i retrieve it, it is always empty! (although the user has an email of course).

i use this code to retrieve the user:
$user = new User();
$user->retrieve_by_string_fields(array('gc_notif_channel_id_c' => $channelID));

and i find the user alright and all the other fields values are ok, except the email1 field is empty!
later i call $user->save(); and the user email1 is deleted because on the retrieve, it was with email1 field as empty.

does anyone know what the problem is?
how could i ever update a user details if the user email1 field is not retrieved ok?

using community rdition 6.5.13
  • Hi, in data/SugarBean.php is the function retrieve_by_string_fields

    /**     * Constructs a select query and fetch 1 row using this query, and then process the row
         *
         * Internal function, do not override.
         * @param array @fields_array  array of name value pairs used to construct query.
         * @param boolean $encode Optional, default true, encode fetched data.
         * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
         * @return object Instance of this bean with fetched data.
         */
        function retrieve_by_string_fields($fields_array, $encode=true, $deleted=true)


    It seems only retrieve fields from own and 'cstm' table, for this reason "email1" is empty.



    Regards,
    Esteban
  • you can see in my post, that i'm already using "retrieve_by_string_fields" function.

    How does anyone ever update the User bean, if it always lack of emails when it is retreived?
    What can i do to update a User bean then?
  • See if this helps:
    HOWTO: Add and retrieve email addresses in a module thru code ( bsoremsugar )
    http://developer.sugarcrm.com/2011/03/08/howto-add-and-retrieve-email-addresses-in-a-module-thru-cod...
    Among other tips it has the following:

    $sea = new SugarEmailAddress;  
    // Grab the primary address for the given record represented by the $bean object 
    $primary = $sea->getPrimaryAddress($bean); 
       
    HTH
    FrancescaS
  • You need call "retrieve_by_string_fields" for search by some field and after you need call "retrieve" method and send the id. This is the best way.



    Try this:
    $tmpUser = new User();
    $tmpUser->retrieve_by_string_fields(array('gc_notif_channel_id_c' => $channelID));
    $user = new User();
    $user->retrieve($tmpUser->id);
    $user->save();


    Regards,
    Esteban





  • Thanks Francesca, works like a charm.