pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
988 stars 665 forks source link

Issue using Set-PnPListItem to update 'Editor' (Modified By) field when using -SystemUpdate #2016

Open bpark1409 opened 5 years ago

bpark1409 commented 5 years ago

Hi,

There is an issue with using Set-PnPListItem to update the 'Editor' (Modified By) field when using the -SystemUpdate parameter - I am using 'PnP PowerShell for SharePoint Online' and have the latest release 3.8.1904.0.

Following the steps below should allow you to reproduce the issue - TEST 4 & 5 FAIL:

# TEST 1 - SUCCESS [Update of a single 'Text' Field without -SystemUpdate]
# Updates 'Title' & creates new version [version: incremented]
Set-PnPListItem -List $List -Identity $ID -Values @{"Title"="Title"}

# TEST 2 - SUCCESS [Update of a single 'Text' Field with -SystemUpdate]
# Updates 'Title' on existing version [version: no change]
Set-PnPListItem -List $List -Identity $ID -Values @{"Title"="Title-1"} -SystemUpdate

# TEST 3 - SUCCESS [Update of just the 'Editor' (Modified By) Field without -SystemUpdate]
# Updates 'Editor' & creates new versin [version: incremented]
Set-PnPListItem -List $List -Identity $ID -Values @{"Editor"="email1@domain.com"}

# TEST 4 - FAIL [Update of just the 'Editor' (Modified By) Field with -SystemUpdate]
# Command completes without error, but the 'Editor' field is not updated [version: no change]
Set-PnPListItem -List $List -Identity $ID -Values @{"Editor"="email2@domain.com"} -SystemUpdate

# TEST 5 - FAIL [Update of the 'Title' & 'Editor' (Modified By) Fields with -SystemUpdate]
# Command completes without error & the 'Title' field is updated on existing version [version: no change], but the 'Editor' field is not updated
Set-PnPListItem -List $List -Identity $ID -Values @{"Title"="Title-2";"Editor"="email2@domain.com"} -SystemUpdate

# TEST 6 - SUCCESS [Update of the 'Title' & 'Editor' (Modified By) Fields without -SystemUpdate]
# The 'Title' and 'Editor' fields are updated on new version [version: incremented]
Set-PnPListItem -List $List -Identity $ID -Values @{"Title"="Title-3";"Editor"="email2@domain.com"}

FYI - I originally tried to raise this on 2nd April with the following comment against a closed issue, but as I have not received any replies I am now raising it as a new issue:

https://github.com/SharePoint/PnP-PowerShell/issues/1413#issuecomment-479223772

Regards.

bpark1409 commented 5 years ago

Hi @erwinvanhunen, I raise this issue 20 days ago, but there have not been any responses, so I am wandering if you could let me know if anyone has been assigned to investigate / fix ? Regards.

mschaaks commented 5 years ago

Hi @erwinvanhunen ,

I did a test with release 3.8.1904.0 trying to update the Editor and Author fields using the systemupdate parameter. The Author field updates fine, however the Editor field remains untouched. Any ideas how to overcome this problem ? I also tried the same using csom code. It seems like something has changed in the CSOM api because in the past it was no problem to set the Editor field using the systemupdate.

erwinvanhunen commented 5 years ago

Hi!

In order to update the editor and author you do not have to use the system update switch. We have in the mean time done an update to the cmdlet which enables you to set both the editor and author (or only one of them). The trick is that you always need to set both. If you want to change only one you need to set it again with the same value at the same time you update the other. We added that logic to the cmdlet.

bpark1409 commented 5 years ago

Hi @erwinvanhunen, Thanks for your reply - I have carried out some more tests to try to update the Editor field using the 'trick' you suggested (TEST 3), but it is still not updating … Summary of my tests below:

# TEST 1 - SUCCESS [Update of just the 'Editor' (Modified By) Field WITHOUT -SystemUpdate]
# Updates 'Editor' & creates new versin [version: incremented]
Set-PnPListItem -List $List -Identity $ID -Values @{"Editor"="email1@domain.com"}

# TEST 2 - FAIL [Update of just the 'Editor' (Modified By) Field WITH -SystemUpdate]
# Command completes without error, but the 'Editor' field is not updated [version: no change]
Set-PnPListItem -List $List -Identity $ID -Values @{"Editor"="email2@domain.com"} -SystemUpdate

# TEST 3 - FAIL [Update both the 'Editor' (Modified By) and 'Author' Fields WITH -SystemUpdate]
# Command completes without error, but  only the 'Author' field is updated - The 'Editor' field is not updated [version: no change]
Set-PnPListItem -List $List -Identity $ID -Values @{"Author"="email2@domain.com";"Editor"="email2@domain.com"} -SystemUpdate

Can you please let me know if I have understood the 'trick' that you suggested to set both the 'Author' and 'Editor' fields at the same time, as it does not seem to be working?

bpark1409 commented 5 years ago

Hi @erwinvanhunen,

I have just updated to the latest version (3.9.1905.3), but this is still an issue.

I raised the question above regarding the 'trick' that you suggested 19 days ago, but have not yet received any response - Can someone please let me know if this is being investigated?

Regards.

bpark1409 commented 5 years ago

Hi @erwinvanhunen,

I have just checked the latest version (3.10.1906.0) and this is still an issue.

The last response I received on this was on 2nd May - Is there something else that I need to do to request an update on progress with resolving this issue?

Regards.

avi081265 commented 5 years ago

Hello All,

Has anyone resolve the issue of updating Editor field.

I also tried without Set-PnPListItem as mentioned below, but not able to update Editor field. Only able to update Author field. I am ok with following if someone help in following code to update Editor field.

`$user = $ctx.Web.EnsureUser("domain\pa384959") $ctx.Load($user) $ctx.ExecuteQuery()

$lookupValue = @() if($user -ne $null){ $spuserValue = New-Object Microsoft.SharePoint.Client.FieldUserValue $spuserValue.LookupId = $user.id $lookupValue += $spuserValue } $userValue = [Microsoft.SharePoint.Client.FieldUserValue[]]$lookupValue

$Item["Author"] = $userValue $Item["Editor"] = $userValue $Item.SystemUpdate()`

bpark1409 commented 5 years ago

Hi @erwinvanhunen,

We are still unable to set the Editor (Modified By) field when we use -SystemUpdate with Set-PnPListItem?

Can you please confirm if anybody is looking at a resolution?

Regards.

tstojecki commented 5 years ago

Setting Editor (Modified By) with -SystemUpdate will NOT work and that is by design:

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ms479448(v=office.15)?redirectedfrom=MSDN

Updates the database with changes that are made to the list item without changing the Modified or Modified By fields.

If you need to update Editor without a new version, you need to call UpdateOverwriteVersion() which Set-PnPListItem does not. It either calls .Update() or .SystemUpdate() https://github.com/erwinvanhunen/PnP-PowerShell/blob/2971423a8461ad99953a19a7f0f37f3980d9a578/Commands/Utilities/ListItemHelper.cs#L212

Note that calling UpdateOverwriteVersion will change the Modified date, so if you want to preserve that you will need to set it back to the previous value yourself

 listItem["Modified"] = modifiedDate;
 listItem["Editor"] = new FieldUserValue() { LookupId = user.Id };
 listItem.UpdateOverwriteVersion();
 ctx.ExecuteQuery();

Seems like Set-PnPListItem should have an extra option e.g. -UpdateOverwriteVersion in addition to -SystemUpdate for completeness @erwinvanhunen

Craig-Humphrey commented 3 years ago

This appears to be still an issue in PnP, recently re-reported HERE and HERE.

For those of us writing content migration scripts, this functionality is vital. Having to run both PnP and standard SPO PowerShell is a pain, especially as the standard cmds don't support retries and the exponential back-off that's needed for bulk actions in SPO.