I am trying to fetch list items along with its Attachments and display on a SharePoint page using JavaScript JSOM.

My code contains the pagination too which is mentioned here.

Now, for attachment we have to load the AttachmentFiles field separately. So what I did is,

context = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);
list = context.get_web().get_lists().getByTitle(ListName);
camlQuery = new SP.CamlQuery();
spItems = list.getItems(camlQuery);
context.load(spItems,'Include(AttachmentFiles,and all remaining fields)');
// My codes );

As mentioned in managePagerControl() method in given link, I have following code:

if (spItems.get_listItemCollectionPosition()) { 
        nextPagingInfo = spItems.get_listItemCollectionPosition().get_pagingInfo(); 
    } else { 
        nextPagingInfo = null; 

Now, this code gives error,

The property or field 'ListItemCollectionPosition' has not been initialized. It has not been requested or the request has not been executed

So, How to get rid of this error or How can I include ListItemCollectionPosition field too in my request? using ViewFields too give same error.


You can include it like below.

clientContext.Load(listItems,items => items.Include(item => item.Id), items => items.ListItemCollectionPosition);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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