Question

Unfortunately, I am stuck in a SP 2013 world now. I know batch operations (using REST APIs) are only supported in SharePoint 2016+ and in SPO. Pnp Js also has a good batch processing extension methods. So, below are my queries:

  1. Does the pnp Js batch processing support SP 2013?
  2. What is the preferred way for batch processing (specifically adding items in SP 2013)? Should i ditch REST API to use JSOM for batching?
Was it helpful?

Solution

  1. No, pnpjs uses the OOTB batching functionality that is not found in SP2013.
  2. Depends on what you are doing, but if you need to add a lot of items using JSOM might be your best bet as you can batch multiple requests this way.

HTH,

Patrick

OTHER TIPS

Adding to what Patrick says, PnP JS is a wrapper over the existing REST API implementation along with some utilities and helper methods.

It will work the way a native endpoint works, so if an endpoint is not supported in SP 2013, it wont work with PnP JS.

In this specific case, Batch endpoint is not supported in 2013, so it wont work with PnP JS. However, the same endpoint will work with 2016+ and SPO.

Secondly, would suggest to keep using REST API. We do have native Promise.All method which gets resolved once all the promises are done.

You can integrate it with PnP JS something like:

var items = [];

for (var i = 0; i < 100; i++) {
    pnp.sp.web.lists.getByTitle("Custom List").items.add({
        Title: "Title" + i,
        Description: "Description"
    });
}

await Promise.all(items).then(function() {
    console.log("100 items were created");
});

More info - Promise API

JSOM is kinda deprecated in the sense that MS is not investing in it anymore. If you plan to migrate the solution to 2016+ or SPO, then you should keep using REST IMHO.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top