You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm authenticating with pnp-auth package using credentials which uses @pnp/sp-commonjs (v2.15.0).
Node version is 20.12.2.
Question/Request
Hello and appologies for my English - it's isn't my first (or second) language even.
I need to update 3 lists in one batch in a service which run daily and I'm getting the famous "This query is already part of a batch" error.
Already had searched about it, read all mentions to it (docs, threads, etc) I've found. Now, I'm in the "begging for help" phase.
So, my service has the follow structure (simplified for brevity):
asyncfunctionhandleAnomalies(sp: SharePoint,batch: SPBatch,actionsToUpdate: any[]){constlist=sp.web.inBatch(batch).lists.getByTitle('List1')// handle all logic and, after, inside a for loop, attempt to add the item to update:awaitlist.items.getById(anomaly.Id).update({ Status })}asyncfunctionhandleActions(sp: SharePoint,batch: SPBatch){constlist=sp.web.inBatch(batch).lists.getByTitle('List2')constnotification : any[]=[]// these are the items that will be formated and inserted into another list latterconstactionsToUpdate: any[]=[]// these are the list items needed to updatefor(const{ Id, Status }ofactionsToUpdate){awaitlist.items.getById(Id).update({ Status })}return{ actionsToUpdate, notification }}asyncfunctionhandleNotifications(sp: SharePoint,batch: SPBatch,notification: any[]){constlist=sp.web.inBatch(batch).lists.getByTitle('List3')// format each notification and attempt to add it to list items (always using the batch) in a for loopawaitlist.items.add({PeopleId: {results: PeopleId}, Title, Body, Reason })// PeopleId is an array of ids}asyncfunctionhandle(){constsp=newSharePoint()// this is a class that handle authentication and exposes pnpjs functionalitiesconstbatch=awaitsp.web.createBatch()const{ actionsToUpdate, notifications }=awaitthis.handleActions(sp,batch)awaitthis.handleAnomalies(sp,batch,actionsToUpdate)awaitthis.handleNotifications(sp,batch,notification)awaitbatch.execute()}
The error occurrs if more than 1 sub-functions have any item to add or update, the next function fail with "This query is already part of a batch" (the first runs ok but the follow function fail).
If anyone could be kind enough to point me where/what I'm doing wrong and help me with this, I'll deeply appreciate. Good day/afternoom/evening to all.
PS: I'm aware that v2 isn't supported anymore but, anyway, ya all get my point...
The text was updated successfully, but these errors were encountered:
Hi, have you reviewed this comment from this previous issue? I suspect the answer here applies to your situation as you are using the same queryable in each of your batches (sp.web).
Sorry the delay but I had to wait a couple days to have some data to run the test.
Worked but, for future reference, chain .inBatch before the action as sugested, didn't work - I had to keep it before the lists method e.g.:
What version of PnPjs library you are using
2.x (No longer supported)
Minor Version Number
2.15.0
Target environment
NodeJS
Additional environment details
I'm authenticating with pnp-auth package using credentials which uses @pnp/sp-commonjs (v2.15.0).
Node version is 20.12.2.
Question/Request
Hello and appologies for my English - it's isn't my first (or second) language even.
I need to update 3 lists in one batch in a service which run daily and I'm getting the famous "This query is already part of a batch" error.
Already had searched about it, read all mentions to it (docs, threads, etc) I've found. Now, I'm in the "begging for help" phase.
So, my service has the follow structure (simplified for brevity):
The error occurrs if more than 1 sub-functions have any item to add or update, the next function fail with "This query is already part of a batch" (the first runs ok but the follow function fail).
If anyone could be kind enough to point me where/what I'm doing wrong and help me with this, I'll deeply appreciate. Good day/afternoom/evening to all.
PS: I'm aware that v2 isn't supported anymore but, anyway, ya all get my point...
The text was updated successfully, but these errors were encountered: