$u = new User();
$u->retrieve_by_email_address($email_addr);
once you have the user bean you can get what you need.
FrancescaS
Even if it's a Sugar CE 6.5 Topic, is good to know how to do it in Sugat 7 too, using javascript
The complete code in Sugar 7 is:
var userEmail = ''
var moduleName = "Users";
var filters = [{id: app.user.get("id")}];
var Users = App.data.createBeanCollection(moduleName)
var req = Users.fetch({"filter": filters});
req.xhr.success(function (data) {
if (data.records.length > 0) {
// console.debug(data)
userEmail = data.records[0].email[0].email_address
}
});
// email object structure
email[0]
email_address "email@example.com"
invalid_email false
opt_out false
primary_address true
reply_to_address false
Hi Francesca,
That worked nice for me. Thank you !
And how could I detect if there are more than a user with the same email ?
Kind regards,
Ibon
Good question, I suppose we all assume that email is unique and no two users have the same email address...
Looking at the retrieve_by_email_address function in modules/Users/User.php it certainly seems that is the assumption.
FrancescaS
Many thanks Francesca.
best regards,
Ibon
Hi All,
As of the latest Sugar releases, you should use:
$sea = BeanFactory::newBean('EmailAddresses');
$sea->getBeansByEmailAddress($emailAddress);
More information on the various ways to work with email addresses can be found here: