문제

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.

도움이 되었습니까?

해결책

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());
  }
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top