Please specify what version of the library you are using: [ 1.3.2 ]
Please specify what version(s) of SharePoint you are targeting: [ SharePoint Online ]
In a single batch operation, I specify to checkout a file, edit the associated listitem and check the file in again, in that order, using the following code:
let updateBatch = sp.createBatch();
var batchListItem = sp.web.lists.getById(listId).items.getById(itemId.ID);
batchListItem.file.inBatch(updateBatch).checkout().then(() => console.log("Checked out"));
batchListItem.inBatch(updateBatch).update(data).then(() => console.log("Item updated"));
batchListItem.file.inBatch(updateBatch).checkin("", CheckinType.Major).then(() => console.log("Checked in again"));
await updateBatch.execute();
The batch request that is created, puts the checkout and checkin actions first, and then updates the item, resulting in an error, because the file is not checked out.
Here below a slightly stripped down version of the generated request payload:
--batch_7...
Content-Type: multipart/mixed; boundary="changeset_9..."
--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary
POST https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1)/file/checkout HTTP/1.1
--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary
POST https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1)/file/checkin(comment='',checkintype=1) HTTP/1.1
--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1) HTTP/1.1
accept: application/json
content-type: application/json;odata=verbose;charset=utf-8
if-match: *
x-clientservice-clienttag: PnPCoreJS:@pnp-1.3.2
{"__metadata":{"type":"SP.Data.PagesItem"},"field":"value"}
--changeset_9...--
--batch_7...--
Hi @bjdekker, thanks! Looks like a bug. We should have to take a look at this case.
I haven't taken the time to really look into this yet, but I suspect I know why it is happening within the library. We have to wait for the update operation to pre-flight some info (the list item type) so in timeline that operation gets added after the others. Agree a bug, but will I think be a hard one to address quickly.
Thanks for the replies, knowing this, it isn't that hard to put these actions in two separate, sequential batches as a work around
I bet you all thought I forgot about this :). I think I have this sorted out now. Need to do some more testing and code cleanup as I had to make some changes within the pipeline which always scares me - BUT I think I finally have ordering fully sorted out.
Most helpful comment
I bet you all thought I forgot about this :). I think I have this sorted out now. Need to do some more testing and code cleanup as I had to make some changes within the pipeline which always scares me - BUT I think I finally have ordering fully sorted out.