PnP PowerShell Set-PnPListItem : Save Conflict.

%3CLINGO-SUB%20id%3D%22lingo-sub-50856%22%20slang%3D%22en-US%22%3EPnP%20PowerShell%20Set-PnPListItem%20%3A%20Save%20Conflict.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50856%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20I%20am%20learning%20PnP%20PowerShell%2C%20and%20a%20simple%20use%20case%20of%20iterating%20a%20list%20and%20updating%20fields%20on%20each%20list%20item%20based%20on%20other%20fields%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20frequently%20getting%20a%20%22Save%20Conflict%20Your%20changes%20conflict%20with%20those%20made%20concurrently%20by%20another%20user.%20If%20you%20want%20your%20changes%20to%20be%20applied%2C%20click%20Back%20in%20your%20Web%20browser%2C%20refresh%20the%20page%2C%20and%20resubmit%20your%20changes.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20updating%203%20fields%20on%20a%20list%20item%2C%20and%20there%20are%20SPD%20workflows%20associated%20with%20the%20items%20(on%20change).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20the%20Set-PnPListItem%20updating%20all%20of%20the%20values%20at%20once%2C%20or%20making%203%20separate%20changes%3F%20%26nbsp%3BI've%20never%20had%20an%20issue%20doing%20this%20with%20regular%20non-PnP%20scripts%2C%20and%20I%20dont%20really%20understand%20where%20the%20conflict%20is%20coming%20from.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%20%20%20%20Get-PnpListItem%20-List%20%22My%20List%22%20-PageSize%2025%20%7C%20%25%20%7B%0A%0A%20%20%20%20%20%20%20%20if(%24_.FieldValues.CustomerID%20-ne%20%24_.FieldValues.Customer_x003a__x0020_DISPLAY_ID%20-or%20%24_.FieldValues.LegacyID%20-ne%20%24_.FieldValues.Customer_x003a__x0020_LEGACY_ID)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Updating%22%20-ForegroundColor%20Red%0A%20%20%20%20%20%20%20%20%20%20%20%20%24metadata%20%3D%20%40%7B%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%24metadata.Add(%22ForceUpdate%22%2C%2299999%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%24metadata.Add(%22CustomerID%22%2C%22%24(%24_.FieldValues.Customer_x003a__x0020_DISPLAY_ID)%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%24metadata.Add(%22LegacyID%22%2C%22%24(%24_.FieldValues.Customer_x003a__x0020_LEGACY_ID)%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20Set-PnPListItem%20-List%20%22My%20List%22%20-Identity%20%24_.Id%20-Values%20%24metadata%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-50856%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-50864%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20PowerShell%20Set-PnPListItem%20%3A%20Save%20Conflict.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50864%22%20slang%3D%22en-US%22%3EAccording%20to%20the%20code%2C%20Set-PnPListItem%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FCommands%2FLists%2FSetListItem.cs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FCommands%2FLists%2FSetListItem.cs%3C%2FA%3E%3CBR%20%2F%3Edoes%20only%20one%20ExecuteQuery%20for%20each%20item%20(including%20all%20the%20fields).%20I'd%20suggest%20that%20you%20try%20same%20code%20with%20another%20list%20without%20workflows%20associated%20to%20the%20%22on%20change%22.%3C%2FLINGO-BODY%3E
Highlighted
Valued Contributor

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          
        }
    }
1 Reply
Highlighted
According to the code, Set-PnPListItem
https://github.com/SharePoint/PnP-PowerShell/blob/master/Commands/Lists/SetListItem.cs
does only one ExecuteQuery for each item (including all the fields). I'd suggest that you try same code with another list without workflows associated to the "on change".