Forum Discussion

Brent Ellis's avatar
Brent Ellis
Silver Contributor
Mar 07, 2017

PnP PowerShell Set-PnPListItem : Save Conflict.

So I am learning PnP PowerShell, and a simple use case of iterating a list and updating fields on each list item based on other fields

 

I am frequently getting a "Save Conflict Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes."

 

This is updating 3 fields on a list item, and there are SPD workflows associated with the items (on change).

 

Is the Set-PnPListItem updating all of the values at once, or making 3 separate changes?  I've never had an issue doing this with regular non-PnP scripts, and I dont really understand where the conflict is coming from.

 

    Get-PnpListItem -List "My List" -PageSize 25 | % {

        if($_.FieldValues.CustomerID -ne $_.FieldValues.Customer_x003a__x0020_DISPLAY_ID -or $_.FieldValues.LegacyID -ne $_.FieldValues.Customer_x003a__x0020_LEGACY_ID){
            Write-Host "Updating" -ForegroundColor Red
            $metadata = @{}
            $metadata.Add("ForceUpdate","99999")
            $metadata.Add("CustomerID","$($_.FieldValues.Customer_x003a__x0020_DISPLAY_ID)")
            $metadata.Add("LegacyID","$($_.FieldValues.Customer_x003a__x0020_LEGACY_ID)")

            Set-PnPListItem -List "My List" -Identity $_.Id -Values $metadata          
        }
    }

Resources