Pnp-powershell: Add-PnpListItem / Set-PnPListItem only updates one lookup field at time

Created on 26 Jan 2018  路  8Comments  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

When you add or update a listitem, only one lookup column is updated and some other normal fields, depends on (maybe?) the name of the field.

Expected behavior

The operation should save the value of every field passed in the Values hashtable

Actual behavior

It only updates some fields until it gets the lookup field. After that, no other value is updated.
Same with Set-PnpListItem.

Current workaround: Add-PnPListItem, then a Set-PnPListItem for each lookup value.

image

"Detalle" column and "Cosa" column are lookups. "Cal" is a number field.

I couldn't determine why some fields are updated with some lookups (like Cosa let Cal get value but not Detalle. And Detalle and Cal didn't work together). I thing it may be some alphabetical order, because in previous tests Title never got value. Another thing: ContentType parameter didn't affect. Same behavior with it, and without.

For each item, these are the pnp commands ran.

Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 1"; "Detalle" = "5"; "Cosa"="3"; } -ContentType "Elemento"

$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 2"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; "Cosa"="3"; "Cal"="2.1";}

$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 3"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; "Detalle" = "5"; "Cal"="2.1";}

$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 4"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; }
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; }

$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 5"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; "Cal"="2.1";}
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; }

$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 6"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; }
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; "Cal"="2.1";}

Steps to reproduce behavior

  • Create a couple simple lists
  • Create another list with lookup columns to the simple lists and some normal fields
  • Add a listitem using Add-PnPListItem, including lookup fields. Only one lookup field and maybe some columns will get info
  • Update a listitem using Set-PnpListItem, including lookup fields. Only one lookup field and maybe some columns will get info.

Which version of the PnP-PowerShell Cmdlets are you using?

  • [X] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

2.22.1801.0

How did you install the PnP-PowerShell Cmdlets?

  • [X] Installed through the PowerShell Gallery with Install-Module

Most helpful comment

I fixed the bug and merged it with the dev branch.

All 8 comments

I am seeing similar behavior to my existing PowerShell script which was working fine with earlier version of PnP PowerShell. Even I tested with version 2.23.1802.0 but still same issue.

Hi,
I experience the same problem, but with Add-PnPFile. v2.22.1801.0.
But how do I get the ID of the just created file?
Greets,
Peter

@Peter-De-Meester I had to take id with this:

$ctx = Get-PnPContext
$newFile = Add-PnPFile -path $file.FullName -folder "Shared documents"
$id = $newFile.ListItemAllFields
$ctx.Load($id)
$ctx.ExecuteQuery()

The you have the $id which you can use to:
set-pnplistitem -list <listnama> -identity $id

Hope this helps :)

After confirming this problem with the latest version, I stepped back until I found one that appears to work, which is 2.19.1710.1. All versions since appear to be broken in some way for Add-PnpListItem.

Looking at the commit history, I see item handling was refactored on Nov 19. Possibly a bug introduced here.

Hi Kallejar & NoahStahl,
Thanks both for the comment. While waiting for a solution, I'll use the workaround.
Greets,
Peter

I'll have a look at it.

I found the bug and will work on an update

I fixed the bug and merged it with the dev branch.

Was this page helpful?
0 / 5 - 0 ratings