pnp / PnP-PowerShell

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

Get-PnpListItem with -UniqueId does not return the item #2343

Open ikarstein opened 4 years ago

ikarstein commented 4 years ago

Reporting an Issue or Missing Feature

Issue

Expected behavior

Get List Item from SPO with UniqueID using cmdlet Get-PnpListItem -List "abc" -UniqueId "2875f838-8c6f-4de1-9655-72f37f5c345d"

Actual behavior

cmdlet returns $null

Steps to reproduce behavior

$item = Get-PnpListItem -List "abc" -Id 1
write-host $item.Id # => 1
$item2 = Get-PnpListItem -List "abc" -UniqueId ($item["UniqueId"])
write-host $item2.Id # => no result

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

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

3.14.1910.1

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

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

ikarstein commented 4 years ago

This works:

$item = Get-PnpListItem -List "abc" -Id 1
$list = Get-PnpList -Identity "abc"
$item3 = $list.GetItemByUniqueId($item["UniqueId"])

(Get-PnPContext).Load($item3)
Invoke-PnPQuery

write-host $item3.Id # => 1
ikarstein commented 4 years ago

I tried with CAML taken from

Commands/Lists/GetListItem.cs

Same result.

BUT when I change the FieldRef from "GUID" (as it is in the source currently) to "UniqueId" I get the result.

Not working:

Get-PnPListItem -List "abc" -Query "<View><Query><Where><Eq><FieldRef Name='GUID'/><Value Type='Guid'>2875f838-8c6f-4de1-9655-72f37f5c345d</Value></Eq></Where></Query></View>"

Working:

Get-PnPListItem -List "abc" -Query "<View><Query><Where><Eq><FieldRef Name='UniqueId'/><Value Type='Guid'>2875f838-8c6f-4de1-9655-72f37f5c345d</Value></Eq></Where></Query></View>"

Looks like a bug in source.

ikarstein commented 4 years ago

Here is a hint to the "BuiltInFieldName":

https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spbuiltinfieldid.uniqueid?view=sharepoint-server

KoenZomers commented 4 years ago

As mentioned in the PR you have filed for this one, even though it feels illogical, this is by design. You should instead use the value from the Guid field:

$item = Get-PnpListItem -List "abc" -Id 1
$item2 = Get-PnpListItem -List "abc" -UniqueId ($item["Guid"])

Then it should work.