Stepping through items on a list (next/previous)

Hi,

I'm building a project review form, and wanted to include a "Next" and "Previous" button (and possibly a dropdown to choose a project id/title to jump to).

I can do a redirect to the current ID +/-1, but wondered if there was a way to check if a particular ID exists, before redirecting to that ID? Or to get a list of item IDs ?

So if I have items with ID 1,2,4,5,7, and I'm on 4, the next won't be a problem (ID+1=5), but previous would be ID-1=3, which no longer exists. Any ideas how to check if 3 exists, and if it doesn't, go to ID-2 instead (and then ID-3 if that doesn't exist)?

This would be a really useful feature that would save our project managers a lot of time!

Regards
Nick

Hello @Nick.Jones,

You can check if specific item exists using PnPjs get action:

var nextID = fd.itemId + 1
pnp.sp.web.lists.getByTitle("NewListForms").items.getById(nextID).get()

And then build a link to redirect user.

Also, we can offer a paid support for adding 'Next' and 'Previous' to the toolbar. Please email us at [email protected] for more details.

1 Like