1

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 Answers 2

0

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>
1
  • Good morning, thank you for your response. This is very similar to the code that I have in my project. It seems that the note fields that are returning null have something in common; they all return a value of 2 when I use the get_versions() method. The list items that show the content from the note field correctly return a value of 1 when the get_versions() method is used.
    – fce_sp
    Commented Apr 21, 2020 at 12:10
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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