sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

RER: 'ChangedItemProperties' not working on Document Library

Open rbarten opened this issue 7 years ago • 17 comments

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

  1. Create an ItemAdding EventReceiver and add values to the ChangedItemProperties.
  2. Add an ItemAdding eventreceiver to a Document Library using PowerShell (Not a Provider hosted app solution)
  3. Use the Copy To functionality.
  4. 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?

rbarten avatar Jul 15 '19 06:07 rbarten

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Jul 15 '19 06:07 msft-github-bot

@andrewconnell : Why does this issue already have the tag 'status:anwered'?

rbarten avatar Jul 16 '19 07:07 rbarten

@rbarten that was a mistake on my part... my bad

andrewconnell avatar Jul 16 '19 11:07 andrewconnell

We have the exact same issue. This was working a month ago. But is not working anymore...

ghost avatar Jul 23 '19 09:07 ghost

@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 avatar Jul 25 '19 06:07 allanped

@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...

andrewconnell avatar Jul 29 '19 12:07 andrewconnell

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?

ghost avatar Jul 30 '19 10:07 ghost

@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?

rbarten avatar Aug 16 '19 12:08 rbarten

@andrewconnell, one of my clients is reporting this issue. What is the current status of this? Is this actively being worked on?

Pieter-Veenstra avatar Sep 03 '19 16:09 Pieter-Veenstra

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.

andrewconnell avatar Sep 03 '19 17:09 andrewconnell

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.

DominickCosgrove avatar Sep 04 '19 07:09 DominickCosgrove

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'

rbarten avatar Sep 23 '19 07:09 rbarten

Same issue on ItemAdding Also, can you please change RERs to be REST services? Microsoft seems to have abandoned WCF long ago.

lvasiliou avatar Nov 04 '19 15:11 lvasiliou

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?

rbarten avatar Jul 27 '20 09:07 rbarten

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.

Biggum82 avatar Dec 16 '21 16:12 Biggum82

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);
                }
            }
        }

dkardokas avatar Aug 30 '23 16:08 dkardokas

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.

github-actions[bot] avatar May 02 '25 14:05 github-actions[bot]