Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a small application that is making use of the SP-COM. I use the following code to get the current users email address:

ctx = SP.ClientContext.get_current();
web = ctx.get_site().get_rootWeb();
currentUser = web.get_currentUser();
currentUser.retrieve();
currentUser.get_email()

Strange enough, for a couple of users the email addresse is not retrieved, even though the user has an email address when I look at the users settings-page. Looking at the json, that is coming back from the server, the email-address is also blank.

Any hints what I might be missing here?

share|improve this question
add comment

1 Answer

The currentUser.retrieve() is not meant to be used from code. It is reserved for internal purposes.

Also, are you using the load() and executeQueryAsync() methods which are required to fetch the data with the Client Object Model?

Try the following code:

    context = new SP.ClientContext.get_current();
    web = context.get_web();
    this._currentUser = web.get_currentUser();
    context.load(this._currentUser);

    context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),Function.createDelegate(this, this.onFailureMethod));

    function onSuccessMethod(sender, args) {

    alert(this._currentUser.get_email());

    }

    function onFailureMethod(sender, args) {

    alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());

    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.