Pnpjs: Unclear how to page through a getlistItemChangesSinceToken

Created on 7 Oct 2018  路  8Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ latest ]

Please specify what version(s) of SharePoint you are targeting: [ on-premise, no idea which actual version ]

Expected / Desired Behavior / Question

I'm trying to avoid downloading tens of MB in one go, so I want to use RowLimit. This works to get me only 5 changes at a time:

await list.getListItemChangesSinceToken({RowLimit: "5"})

I then get XML back including

<rs:data ItemCount="5" ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=5">

But I can't figure out where to put this value. Some docs I found say that it needs to be passed as

<Paging ListItemCollectionPositionNext="X" />

but neither Paging nor ListItemCollectionPositionNext are accepted by SP.

Any idea on how to make this work?

code answered question

Most helpful comment

Hi @wmertens
You can do like this:
Make sure you have the "&amp;" which is the "&".
const response = await sp.web.lists.getByTitle('LISTNAME').getListItemChangesSinceToken({QueryOptions: '<Paging ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=5" />'});

Let me know how it works out :)

All 8 comments

Hi @wmertens
You can do like this:
Make sure you have the "&amp;" which is the "&".
const response = await sp.web.lists.getByTitle('LISTNAME').getListItemChangesSinceToken({QueryOptions: '<Paging ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=5" />'});

Let me know how it works out :)

Great, thank you! :)
Pretty hard to figure out - I wonder how/where this should be documented so it's clear for future searchers.

@wmertens No probs! Yes, I just remembered struggling with special characters before in querys.

This has to do with special characters and XML, that you need to escape them in some way.
Maybe we need to add in some documentation. But I'm not sure where.
@koltyakov @patrick-rodgers Any suggestions? :)

Might fit below the paged items section on the items page. You could just use getListItemChangesSinceToken as the header.

I'll try to have a look at it tomorrow!

Closing this as the docs page is now updated. Thanks @simonagren for taking care of that :)

I finally got around to testing this (in v1) and I needed to replace the & in the token with &amp; BUT NOT replace the =.

Apart from that, getListItemChangesSinceToken doesn't page properly. I explain the problem here: https://sharepoint.stackexchange.com/questions/273247/listitemchangessincetoken-doesnt-page-correctly

It would be great if someone from here could chime in on that - I hope I'm simply doing something wrong but I fear the API is just broken.

Update: I somehow missed that getChanges also has token support, it's way easier to use, and it gets changes that getlistItemChangesSinceToken doesn't get.

To use a token, pass ChangeTokenStart: {StringValue: token}. You can get the initial token with

            const {
                CurrentChangeToken: {StringValue: token},
            } = await list.get()

You can also pass FetchLimit: "100" (yes, as a string) to get changes 100 at a time; read the token from the last item.

Was this page helpful?
0 / 5 - 0 ratings