Replies: 4 comments
-
I can start by explaining this "Initially I tried using UpdateOverwriteVersionBatchAsync for the field value updates and RecycleByIdBatchAsync for the recycling, but then on executing the batch, all the CSOM requests failed saying the item didn't exist - because in fact the recycle requests were issued first (despite me adding them to the batch last)." This is because UpdateOverwriteVersion under the covers uses CSOM, while RecycleById uses REST and SharePoint batching cannot mix things. What we do is split up the batch you provided and create separate Graph, REST and CSOM batches and execute those. |
Beta Was this translation helpful? Give feedback.
-
If you're combine UpdateBatchAsync and RecycleByIdBatchAsync then they'll be executed in the correct order...not sure though if UpdateBatchAsync is sufficient for your needs? |
Beta Was this translation helpful? Give feedback.
-
If you don't have an IListItem you can always consider crafting your API requests manually and batch them, see https://pnp.github.io/pnpcore/using-the-sdk/basics-customapirequests.html for details on how to do that |
Beta Was this translation helpful? Give feedback.
-
Yes I understand how it's implemented, I'm more curious why it's designed that way and whether it couldn't be improved... |
Beta Was this translation helpful? Give feedback.
-
I have a list and a bunch of ids (potentially 1000s - really depends what the user is trying to do), and for all them I need, in a single operation, to use UpdateOverwriteVersionAsync( ) to update them all to have the same new field value. I know there's UpdateOverwriteVersionBatchAsync( ) but that requires an IListItem, and I don't have such a thing (only the id). Would I have to do another query first to "fetch" all the IListItem objects just to do this?
If it can be done with just regular update that does create a version, that might be OK in this case too.
I don't otherwise need the IListItem.
I guess I was hoping for some sort of "UpdateByIdBatchAsync" function on IListItemCollection...after all I can see that UpdateOverwriteVersionBatchAsync( ) only needs the Id (and the field name/value) to do its job.
I can see how, for instance, RecycleByIdImplementation( ) is done, but I don't have the ability to make use of the same trick with only public access to the PnP library.
It seems in general it would make more sense to be able to expose APIs that allow constructing an empty model for things like lists/items/fields just using the ID/name etc., that don't require server calls. That's essentially how CSOM was designed.
Edit: on further investigation, it's become even harder to see how to do what I actually want, which is to issue a single API call to
a) update a field value for a set of items in a list (that I know the ids for)
b) recycle all those items
Essentially, I need to record some additional information against all the items that will be preserved when they're moved to the recycle bin.
Ideally, it should even be done as an atomic operation (i.e. it either all succeeds, or all fails), but I accept the existing SP APIs don't seem to support that.
Initially I tried using UpdateOverwriteVersionBatchAsync for the field value updates and RecycleByIdBatchAsync for the recycling, but then on executing the batch, all the CSOM requests failed saying the item didn't exist - because in fact the recycle requests were issued first (despite me adding them to the batch last).
Then I tried doing UpdateOverwriteVersionBatchAsync in separate loop, but even then, each time I called list.Items.GetById( ), the batch command seemed to get executed! So it ended up making 2 separate API calls for each item, just to update the field values, which won't scale at all, and risks living the list in an inconsistent state if something goes wrong.
I'm pretty sure the above can be done with a single API call to Sharepoint, but the PnP library seems to make it very difficult to do...
Beta Was this translation helpful? Give feedback.
All reactions