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 am creating a Hosted app using NAPA on Sharepoint 2013 (Office365). I need to retrive a user from a list column and get the user's email.

SP.List.getItems with a query returns a listEnumerator correctly. However, the user field is of type SPFieldUserValue. This does not appear to have a property called User from which I can retrieve the email (the C# version of SPFieldUserValue has a User property). Any idea on how I can get the user's email in javascript?

share|improve this question

2 Answers 2

This query will give you Author column (user) with email from a list 'Test':

/_api/Web/Lists/GetByTitle('Test')/Items?$select=Author/EMail&$expand=Author/EMail

You can replace 'Author' with any other Person/Group column.

share|improve this answer

I think that you need to use SP.Web.ensureUser method to retrieve user by it's logon name, after this you can use SP.User.email property.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

function sharePointReady() {
    //retrieve logonName

    var clientContext = SP.ClientContext.get_current();
    var web = context.get_web();
    var user = web.ensureUser(logonName);

    clientContext.load(user);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() {
    alert('The email address of the current user is ' + user.get_email());
    alert('The account name is ' + user.get_loginName());
}
function onQueryFailed(sender, args) {
    alert('Error: ' + args.get_message());
}
share|improve this answer
    
Thanks. I'm trying to get the email of a user from a list column, not the current user. Unfortunately, SPFieldUserValue only returns the Display Name and not the logon name. So this won't work. –  Sanat Gersappa May 17 '13 at 5:18
    
you also can try to use User Information List. See this example. It should store user's email. –  Alexander May 17 '13 at 6:46

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.