質問

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