From 20fe6e4ce2c53b71c28627ada5f219bd73540c9a Mon Sep 17 00:00:00 2001 From: jackpoz Date: Fri, 14 Jul 2023 11:29:01 +0200 Subject: [PATCH 1/2] Add -Includes parameter to Get-PnPListItem Add -Includes parameter to Get-PnPListItem preserving the current Get-PnPListItem loaded properties --- src/Commands/Lists/GetListItem.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Commands/Lists/GetListItem.cs b/src/Commands/Lists/GetListItem.cs index 0ef020f5f..b17da8df8 100644 --- a/src/Commands/Lists/GetListItem.cs +++ b/src/Commands/Lists/GetListItem.cs @@ -11,7 +11,7 @@ namespace PnP.PowerShell.Commands.Lists { [Cmdlet(VerbsCommon.Get, "PnPListItem", DefaultParameterSetName = ParameterSet_ALLITEMS)] [OutputType(typeof(ListItem))] - public class GetListItem : PnPWebCmdlet + public class GetListItem : PnPWebRetrievalsCmdlet { private const string ParameterSet_BYID = "By Id"; private const string ParameterSet_BYUNIQUEID = "By Unique Id"; @@ -76,6 +76,8 @@ protected override void ExecuteCmdlet() { ClientContext.Load(listItem, l => l.ContentType, l => l.ContentType.Name, l => l.ContentType.Id, l => l.ContentType.StringId, l => l.ContentType.Description); } + if (RetrievalExpressions.Length > 0) + ClientContext.Load(listItem, RetrievalExpressions); ClientContext.ExecuteQueryRetry(); WriteObject(listItem); } @@ -95,7 +97,9 @@ protected override void ExecuteCmdlet() query.ViewXml = $"{UniqueId}{UniqueId}{viewFieldsStringBuilder}"; var listItem = list.GetItems(query); + // Call ClientContext.Load() with and without retrievalExpressions to load FieldValues, otherwise no fields will be loaded (CSOM behavior) ClientContext.Load(listItem); + ClientContext.Load(listItem, l => l.Include(RetrievalExpressions)); if (IncludeContentType) { ClientContext.Load(listItem, l => l.Include(a => a.ContentType, a => a.ContentType.Id, a => a.ContentType.Name, a => a.ContentType.Description, a => a.ContentType.StringId)); @@ -156,7 +160,9 @@ protected override void ExecuteCmdlet() do { var listItems = list.GetItems(query); + // Call ClientContext.Load() with and without retrievalExpressions to load FieldValues, otherwise no fields will be loaded (CSOM behavior) ClientContext.Load(listItems); + ClientContext.Load(listItems, l => l.Include(RetrievalExpressions)); if (IncludeContentType) { ClientContext.Load(listItems, l => l.Include(a => a.ContentType, a => a.ContentType.Id, a => a.ContentType.Name, a => a.ContentType.Description, a => a.ContentType.StringId)); From b1f5e04fdfefbd150f3324946b737ac0ff0a344c Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Sun, 6 Aug 2023 14:56:32 +0200 Subject: [PATCH 2/2] Adding changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 607dc969b..3aa0d53bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - Added `-MediaTranscription` and `-MediaTranscriptionAutomaticFeatures` to `Set-PnPTenant` which allows for configuring the media transcription settings. [#3238](https://github.com/pnp/powershell/pull/3238) +- Added `-Includes` option to `Get-PnPListItem` which allows for specifying additional fields to be retrieved. [#3270](https://github.com/pnp/powershell/pull/3270) ### Fixed