Pnpjs: Trying to use .add with batching more than once results in "This query is already part of a batch."

Created on 11 Oct 2018  路  3Comments  路  Source: pnp/pnpjs

Category

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

Version

Please specify what version of the library you are using: [ pnp/sp 1.2.1]

Please specify what version(s) of SharePoint you are targeting: [SPO]

Expected / Desired Behavior / Question

I'm looping through an array of items and, where each item contains the 'newLink' property, I want to add a task to the current batch to add the item to the list in question.

Observed Behavior

the first 'add' task is successfully added to the batch, all subsequent attempts result in the error "This query is already part of a batch."

queryable.ts:228 Uncaught Error: This query is already part of a batch.
at class_1.ODataQueryable.inBatch (queryable.ts:228)
at eval (eval at (GlobalNavConfigScreen.tsx:420), :1:28)
at GlobalNavConfigScreen. (GlobalNavConfigScreen.tsx:420)
at step (guid.js:57)
at Object.next (guid.js:57)
at fulfilled (guid.js:57)

Steps to Reproduce

const batch = new Web(this.props.globalNavListsUrl).createBatch();
const actions = new Web(this.props.globalNavListsUrl).lists.getByTitle(this.props.rowListName).items;
for (const category in this.state.onSaveOrdersAdditions) {
this.state.onSaveOrdersAdditions[category].forEach(async (link, index) => {
if (link.newLink) {
actions.inBatch(batch).add({
Title: link.Title,
URL: link.URL,
Order0: index,
Category: link.Category
});
}
});
}

code details needed question

All 3 comments

Can you have a look at the example on adding multiple items using batching and see if that gets you sorted? I think you want to make your "actions" variable the list instance and each add would be actions.items.add(...)

That did the trick; thanks!

Great, going to close the issue then, glad to hear its working. Thanks!

Was this page helpful?
0 / 5 - 0 ratings