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]
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.
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
at GlobalNavConfigScreen.
at step (guid.js:57)
at Object.next (guid.js:57)
at fulfilled (guid.js:57)
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
});
}
});
}
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!