2

I have created the SharePoint hosted app.

I'm using JSOM for App.

I'm retrieving items from the list.

I have default column in the list called Author (Created by).

I want to retrieve email address of that Author.

2

You can use the below sample code. It gets the item by its ID, then get the created by field and then ensures the user exits in site collection using web.EnsureUser. After that, we can use the email property.

var clientContext = new SP.ClientContext();
var item = clientContext.get_web().get_lists().getByTitle("Custom List").getItemById(1);
clientContext.load(item);
clientContext.executeQueryAsync(
  function(){ 
       var createdBy = item.get_item("Author");
       var user = clientContext.get_web().ensureUser(createdBy.get_lookupValue());
       clientContext.load(user);
       clientContext.executeQueryAsync(
            function(){ 
                 var email = user.get_email();   
                 console.log("User Email: " + email);
            },function(sender,args){ 
                 console.log(args.get_message());
            }
       );
  },
  function(sender,args){ 
       console.log(args.get_message());
  }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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