문제

I have built a SharePoint app that allows users to construct a query, run it, and export the results as an xlxs file. It seems that all the parts of the app work exactly as I intended, with the exception of the fields where typeAsString = Note.

For many of the results (not all) these fields are blank. It seems to be because get_item("my_note_field") is returning null.

Why would get_item() return null for some and not for others?

Please note: I have confirmed from the source list that there are notes in the list items I am getting returned from the query.

Update: I have found that using the get_versions() method on a list item returns a value of 2 for every list item that is returning a null value. The list items that return the note field value all have a get_versions() return of 1.

도움이 되었습니까?

해결책 2

The reason the the note field was displaying a null value was because there was more than one version of the comment field. When I used item.get_item("my_note_field") it was returning the most recent note. I needed to load the previous versions of the column in order to get the correct field value.

다른 팁

You’d better provide detailed solution so we could try to research. My test code,it works well:

 <script>
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
    var context =  SP.ClientContext.get_current();  
       var web = context.get_web();  
       var list = web.get_lists().getByTitle("test");  
       var query = new SP.CamlQuery(); 
       context.load(list);  
       query.set_viewXml(”<View><Query></Query><ViewFields><FieldRef Name='my_note_field' /></ViewFields></View>”);  
       var items = list.getItems(query);  
       context.load(list);  
       context.load(items, 'Include(my_note_field)');  
       context.executeQueryAsync(  
        Function.createDelegate(this, function () {  
            var enumerator = items.getEnumerator();  
            while (enumerator.moveNext()) {  
                var currentListItem = enumerator.get_current();  
                console.log(currentListItem.get_item("my_note_field"));             
            }  
        }),  
       Function.createDelegate(this, fail)  
     );  
    })
    function fail(){}
    </script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top