RER: 'ChangedItemProperties' not working on Document Library
Category
- [ ] Question
- [ ] Typo
- [x] Bug
- [ ] Additional article idea
Expected or Desired Behavior
When someone is using the 'Copy To' functionality. Also all metadata of the document is copied. We want to prevent this by clearing out particular (custom) columns with an synchronous ItemAdding event receiver. When adding values to the 'ChangedItemProperties' Dictionary of SPRemoteEventResult we would expect that the values of those columns are updated within a ItemAdding Event on a Document Library.
Observed Behavior
This won't work in SharePoint Online, nothing happens when setting these values. Sample code:
SPRemoteEventResult result = new SPRemoteEventResult();
if(properties.EventType == SPRemoteEventType.ItemAdding)
{
result.ChangedItemProperties.Add("cusField", "test");
result.ChangedItemProperties.Add("Title", "test title");
result.Status = SPRemoteEventServiceStatus.Continue;
}
return result;
Steps to Reproduce
- Create an ItemAdding EventReceiver and add values to the ChangedItemProperties.
- Add an ItemAdding eventreceiver to a Document Library using PowerShell (Not a Provider hosted app solution)
- Use the Copy To functionality.
- Event Receiver is triggered, but values are not updated.
If this is not supported. What other options are there to check if Copy To was used? Update the values within a ItemAdded async RER?
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
@andrewconnell : Why does this issue already have the tag 'status:anwered'?
@rbarten that was a mistake on my part... my bad
We have the exact same issue. This was working a month ago. But is not working anymore...
@andrewconnell: Are there any news on this issue? It is breaking functionality for our 200 customers running our system. This was working 4 weeks ago...
@allanped can you post code that was working and is now no longer working? The OP asked a question, but it wasn't indicated that something has recently changed...
We did some further testing on this. We found that it is working when you use the 'Copy to' function between different libraries. Here the only case where it is currently not working is when you use the ‘Copy to’ function to the same library or a folder within that library. @rbarten can you confirm this?
@andrewconnell we have no test cases that confirms that this specific scenario has been working. We basically use the same code as @rbarten posted. Furthermore we had the ParserDisabled = true for the list which we believe was working before. Now it makes no difference if it is true/false. Hope this helps?
@mathildo @andrewconnell I also have the issue when I'm copying files to another document library within the same site. Document in Library X with Title set to 'Test'. ItemAdding RER is attached to this library. Library X: Copy to Library Y => Title stays 'Test' Library Y: Copy to Library X => Title stays 'Test', would expect 'test title'. ItemAdding event is triggered, but ChangedItemProperties is ignored.
Also tried enabling 'ParserDisabled' on the list, same results.
So how can we prevent (or change) Metadata when using this 'Copy To' function?
@andrewconnell, one of my clients is reporting this issue. What is the current status of this? Is this actively being worked on?
I don't have anything to share... I made MSFT aware of it, but haven't heard anything. If it's urgent/time-sensitive, suggest you open a support case through your tenant admin.
Our ISV who's solution our platform is built on has a feature that is built around "ChangedItemProperties" which has stopped working. This is impacting our business from being able to function as expect and is adding significant risk to our business both financially, but also the health and safety of our staff. MS have been made aware via support tickets and have been able to reproduce the issue, but we are getting no traction on getting a fix from MS, despite multiple tickets being open by our ISV and ourselves. Is there away to get this escalated as it has not been resolved in over 6 weeks. As a client of MS we would expect to have some sort of official response, route cause analysis and timeline to resolution.
Any update? Did someone receive a response from MS related to this issue? Are there any workarounds we could implement?
Just found some time to do some more testing and discovered that it does work on ItemUpdating, but doesn't work on ItemAdding. Still unknown is this is 'by design' or a bug.. Not a lot of documentation could be found related to 'ChangedItemProperties'
Same issue on ItemAdding Also, can you please change RERs to be REST services? Microsoft seems to have abandoned WCF long ago.
I checked this issue again, after a long period. And for me it's working 'again'. Did someone received a response from Microsoft related to this issue? Something changed one their end?
Hi, I've simmilar Issue. And this is the only thread related to ChangedItemProperties i've found.
My needs are some kind different to the original post. (Maybe I should open a new thread?) We want to delete some data when a new file is loaded to Document Library. This is because someone uploads a previously downloaded File, the file contets the data of the list item. In order to avoid a replace of the file (for business requeriments), we erase all fields, including "Title", where I'm going to explain what is happening.
Once the file is loaded, and all text fields are cleared (useing empty string ""). These fields are editable. The user can fill information with no problem. The problem comes on a later update of the record. If a user edits the record, the fields affected by ChangedItemProperties who will not be modified, will return to empty string and and the previous edit values will be lost: This also happens when in OnUpdated RER, after listItem.Update() and context.executeQuery are executed.
This happens even uninstalling Add-Inn. Seems like the ChangedItemProperties configuration is atteched to Library List Item permanently.
Expected or Desired Behavior
Upload a new file and clear list fields data.
Observed Behavior The data is cleared on upload and any futher edit of the item if the field is not modified.
Sample Code
public override SPRemoteEventResult ItemAdding(SPRemoteItemEventProperties itemEventProperties, ClientContext clientContext)
{
SPRemoteEventResult res = new SPRemoteEventResult();
res.Status = SPRemoteEventServiceStatus.Continue;
res.ChangedItemProperties.Add("Title", "");
return res;
}
Steps to reproduce:
1- Upload a file to Document Library. 2- Edit the item, filling fields affected by ChangedItemProperties and save. The data is saved correctly. 3- Edit the file again and just save. 4- Edit or display the item and the data is gone.
It's disappointing this still hasn't been addressed (or even triaged by the looks of it) and still causing the same issue in 2023. For those coming across this thread, we have used the following workaround to deal with the bug
if (!string.Equals(eventProperties.ItemEventProperties.BeforeUrl, eventProperties.ItemEventProperties.AfterUrl, StringComparison.InvariantCultureIgnoreCase))
{
var beforeLibrary = eventProperties.ItemEventProperties.BeforeUrl.Split('/').First();
var afterLibrary = eventProperties.ItemEventProperties.AfterUrl.Split('/').First();
if (string.Equals(beforeLibrary, afterLibrary, StringComparison.InvariantCultureIgnoreCase))
{
log.LogInformation($"Copy within same library, update after adding");
_ = UpdateDocNumber(resp, eventProperties.ItemEventProperties.AfterUrl, eventProperties.ItemEventProperties.WebUrl);
return new OkResult();
}
}
In this case we're calling UpdateDocNumber method asynchronously and deliberately not awaiting. This will continue to run after response is returned to SharePoint and item added. It will then find the item and perform the update required.
Obviously this is far from ideal as we're having to instantiate new context and recursively repeat the call until item is available.
Including UpdateDocNumber method as an example, but this would need to be adapted
private async Task UpdateDocNumber(string docNumber, string filePath, string siteUrl)
{
using (var pnpCtx = contextProvider.GetPnPContext(siteUrl))
{
await pnpCtx.Web.LoadAsync(x => x.ServerRelativeUrl);
var fileUrl = pnpCtx.Web.ServerRelativeUrl + "/" + filePath;
var spFile = await pnpCtx.Web.GetFileByServerRelativeUrlAsync(fileUrl);
if (spFile != null)
{
await spFile.LoadAsync(x => x.ListItemAllFields);
spFile.ListItemAllFields["DocumentNumber"] = docNumber;
await spFile.ListItemAllFields.UpdateOverwriteVersionAsync();
}
else
{
Thread.Sleep(new Random().Next(500));
_ = UpdateDocNumber(docNumber, filePath, siteUrl);
}
}
}
Thank you for taking the time to file an issue. We periodically archive older or inactive issues as part of our issue management process, which automatically closes them once they are archived.
If you’d like to understand more about why and how we handle archived (closed) issues, please see Our approach to closed issues.
We appreciate your contribution and if this is still an active issue with the latest SPFx versions, please do resubmit the details. We needed to perform a cleanup, so that we can start with a clean table with a new process. We apologize for the inconvenience this might cause.