2017-11-17 7 views
0

ドキュメントライブラリからファイルのリストを照会しているときに、表示名を取得しようとしています(利用できない場合はSP2010のユーザーのログイン名を取得しようとしています)。 は(私は、この関数は、現在何を返していないことを認識しています。)CSOMのSP.UserからdisplayNameまたはloginNameを取得する

getEvidenceDocuments = function (relativePath) { 
    var clientContext = new SP.ClientContext("/documents"); 
    var oList = clientContext.get_web().get_lists().getByTitle('Documents'); 
    var query = SP.CamlQuery.createAllItemsQuery(); 
    query.set_folderServerRelativeUrl(relativePath); 
    var allItems = oList.getItems(query); 
    clientContext.load(allItems, 'Include(Title, ContentType, File, Author, Editor)'); 
    clientContext.executeQueryAsync(Function.createDelegate(this, function() { 
     var ListEnumerator = allItems.getEnumerator(); 
     var fileCollection = []; 
     while (ListEnumerator.moveNext()) { 
      var currentItem = ListEnumerator.get_current(); 
      var _contentType = currentItem.get_contentType(); 
      if (_contentType.get_name() !== "Folder") { 
       var File = currentItem.get_file(); 
       if (File !== null) { 
        var obj = { 
         title: File.get_title(), 
         name: File.get_name(), 
         author: clientContext.load(File.get_author(), "Title"), 
         modifiedBy: File.get_modifiedBy(), 
         modified: File.get_timeLastModified() 
        }; 

        fileCollection.push(obj); 
       } 
      } 
     } 
     console.log(fileCollection); 
    }), Function.createDelegate(this, function() { console.log("ohoh"); })); 
}; 

は、重要な部分は、基本的にこれです:

var obj = { 
    title: File.get_title(), 
    name: File.get_name(), 
    author: clientContext.load(File.get_author(), "Title"), 
    modifiedBy: File.get_modifiedBy(), 
    modified: File.get_timeLastModified() 
}; 

File.get_modifiedBy()リターンSP.Userオブジェクト、しばらくclientContext.load(File.get_author(), "Title")戻り未定義。

私はこれを行うための正しい方法を知らないので、私はこのページの周りに私のアプローチを構築しました:https://social.technet.microsoft.com/wiki/contents/articles/22156.sharepoint-2010-a-complete-list-of-spfile-operations-using-ecma-script.aspx

、それぞれのSP.User特性のために著者とmodifiedByを解決するために、正しいアプローチであるもの。

答えて

0

現在の作成者&エディタは、そのlistitemのSPFileオブジェクトではなく、ListItemで使用できます。 SPListItem.get_Item("propertyName")に続いてget_lookupValue()を使用すると、このトリックが実行されます。呼が連鎖することができるように

は、次のコードは、すべての必要なフィールドを検索し、遅延オブジェクトを返す:

getEvidenceDocuments = function (relativePath) { 
    var deferred = $.Deferred(); 
    var clientContext = new SP.ClientContext("/documents"); 
    var oList = clientContext.get_web().get_lists().getByTitle('Documents'); 
    var query = SP.CamlQuery.createAllItemsQuery(); 
    query.set_folderServerRelativeUrl(relativePath); 
    var allItems = oList.getItems(query); 
    clientContext.load(allItems, 'Include(Id, Title, ContentType, File, Author, Editor)'); 
    clientContext.executeQueryAsync(Function.createDelegate(this, function() { 
     var ListEnumerator = allItems.getEnumerator(); 
     var fileCollection = []; 
     while (ListEnumerator.moveNext()) { 
      var currentItem = ListEnumerator.get_current(); 
      var _contentType = currentItem.get_contentType(); 
      if (_contentType.get_name() !== "Folder") { 
       var File = currentItem.get_file(); 
       if (File !== null) { 
        var obj = { 
         id: currentItem.get_id(), 
         title: File.get_title(), 
         name: File.get_name(), 
         createdBy: currentItem.get_item("Author").get_lookupValue(), 
         created: File.get_timeCreated(), 
         // author: clientContext.load(File.get_author(), "Title"), 
         modifiedBy: currentItem.get_item("Editor").get_lookupValue(), 
         modified: File.get_timeLastModified() 
        }; 
        fileCollection.push(obj); 
       } 
      } 
     } 
     deferred.resolve(fileCollection); 
    }), Function.createDelegate(this, function() {deferred.reject(); })); 
    return deferred.promise(); 
}; 
関連する問題