I'm working on building a custom form webpart that will be basis for all of our custom forms going forward. A single webpart to handle New, Display, and Edit. This will facilitate our migration from JSLink/JSOM overrides that we currently have in place. I've been searching for a few days and I can't see any conversations about preventing overlapping saves. This was an OTB feature that just worked. I'm using PnP ListItem update to post item updates.

list.items.getById().update (https://pnp.github.io/pnpjs/sp/items.html)

As far as I can tell, there is no detection or error returned that allows me to address overlapping saves.

How would I implement a feature that prevents overlapping saves in my edit form using SPFx/PnP?

-> Update

As per the answer below, I was able to include the etag value from the current item in the single item update. Overlapping saves returned a 412 error. Still working on handling this error because of the format of the error returned isn't as I expected.

I am using this code to call the update and include the etag. In the current item, the etag is stored in 'odata.etag'.

.update(itemProperties, this.props.CurrentItemJSON['odata.etag'])
.then(...MORE CODE HERE)

In the console, I'm getting this message.

Error: Error making HttpClient request in queryable: [412] ::> {"responseBody":{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.ClientServiceException","message":{"lang":"en-US","value":"The request ETag value '\"23\"' does not match the object's ETag value '\"24\"'."}}},"responseHeaders":{}} at parsers.ts:59

  • I realized immediately after posting this that I could do a Modified Date/Time comparison but that would require an additional query just before saving. Is it that simple or is there some other SP method that I'm unaware of?
    – Arknev
    Aug 22 '18 at 19:15

If I understand you correctly you want to prevent a concurrency issue where two people would save the same item and would overwrite date.

With the SharePoint Rest api this is managed with the etag property. If you do a get request, you'll receive an etag value. When you do a patch request you need to provide this value, and if it's not the same as the current value, it will error because it's not the same. There's a very thorough blog post on this concept: https://sympmarc.com/2015/10/23/using-etags-in-sharepoint-rest-calls-to-manage-concurrency-control/

I looked at the docs for PnPjs and in the update multiple items you see that the etag will be set to a "*" saying to ignore concurrency issues:

list.items.getById(1).inBatch(batch).update({ Title: "Batch 6" }, "*", entityTypeFullName).then(b => {

I would assume you are able to do the same with a single update and set it to the correct etag value to prevent concurrency issues.

  • 1
    This is exactly what I was looking for. I'm investigating and will update when I reach a conclusion. Thanks!
    – Arknev
    Aug 24 '18 at 14:35
  • I was able to get the etag for the current item and then include it in the single item update as you surmised. Like this: ItemList.items.getById(listItemId).update(itemProperties, this.props.CurrentItemJSON['odata.etag'])
    – Arknev
    Sep 19 '18 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.