3

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

1

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.

  • Thanks for your input Gautam, indeed Promise.All is a good option to wait execution till everything is added. But this one will still send out 100 calls instead of one call. I guess I need to use JSOM batching and implement in a way that I can easily change it to REST API based when I migrate to SPO or 2016+. – Unnie Nov 1 '18 at 17:24

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.