Fix ETag conflict errors when using ListItemAttachments with DynamicForm #2058
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using the
ListItemAttachmentscontrol to add or remove attachments on a list item being edited withDynamicForm, saving the form resulted in a 412 ETag conflict error:Root Cause
DynamicFormloads a list item and stores its ETag for optimistic concurrency controlListItemAttachments, which modifies the item and changes its ETag on the serverDynamicFormremains unaware of the ETag changeDynamicFormsends the outdated ETag, causing SharePoint to reject the request with a 412 errorSolution
This PR implements a comprehensive solution with two key components:
1. Enhanced SPService Methods
Modified
addAttachment()anddeleteAttachment()inSPService.tsto return the updated item data (including the new ETag) after performing attachment operations. Both methods now:odata.etag2. Component Integration Pattern
Added callback mechanism to
ListItemAttachments:onAttachmentChangecallback prop that receives updated item dataAdded public method to
DynamicForm:updateETag(itemData)method to update the internal ETag stateUsage
Changes
addAttachment()anddeleteAttachment()to return item dataonAttachmentChangecallback prop and implementationupdateETag(itemData)methodBackward Compatibility
All changes are fully backward compatible:
onAttachmentChangecallback is optionalListItemAttachmentscontinues to work without modificationsupdateETagmethod is a new public method that doesn't affect existing functionalityTesting
Tested scenarios:
Fixes #4696
Original prompt
Fixes #2051
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.