Skip to content

Commit

Permalink
Merge pull request #3270 from jackpoz/features/getlistitem-includes
Browse files Browse the repository at this point in the history
Add -Includes parameter to Get-PnPListItem
  • Loading branch information
KoenZomers authored Aug 6, 2023
2 parents dc890d0 + 2501467 commit b5da970
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ 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 `AllowCommentsTextOnEmailEnabled` parameter to `Set-PnPTenant` which allows including the surrounding document context in email notification when user is mentioned in document comments. [#3268](https://github.com/pnp/powershell/pull/3268)
- Added `-Includes` option to `Get-PnPListItem` which allows for specifying additional fields to be retrieved. [#3270](https://github.com/pnp/powershell/pull/3270)
- Added `-AllowCommentsTextOnEmailEnabled` parameter to `Set-PnPTenant` which allows including the surrounding document context in email notification when user is mentioned in document comments. [#3268](https://github.com/pnp/powershell/pull/3268)
- Added `Export-PnPPowerApp` cmdlet which will export a specified PowerApp as zip package. [#2990](https://github.com/pnp/powershell/pull/2990)
- Added `AzureADLoginEndPoint` and `MicrosoftGraphEndPoint` parameters to `Connect-PnPOnline` cmdlet for use in custom Azure environments. [#2925](https://github.com/pnp/powershell/pull/2925)
- Added `-AzureADLoginEndPoint` and `-MicrosoftGraphEndPoint` parameters to `Connect-PnPOnline` cmdlet for use in custom Azure environments. [#2925](https://github.com/pnp/powershell/pull/2925)

### Fixed

Expand Down
8 changes: 7 additions & 1 deletion src/Commands/Lists/GetListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListItem>
{
private const string ParameterSet_BYID = "By Id";
private const string ParameterSet_BYUNIQUEID = "By Unique Id";
Expand Down Expand Up @@ -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);
}
Expand All @@ -95,7 +97,9 @@ protected override void ExecuteCmdlet()
query.ViewXml = $"<View Scope='RecursiveAll'><Query><Where><Or><Eq><FieldRef Name='GUID'/><Value Type='Guid'>{UniqueId}</Value></Eq><Eq><FieldRef Name='UniqueId' /><Value Type='Guid'>{UniqueId}</Value></Eq></Or></Where></Query>{viewFieldsStringBuilder}</View>";

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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b5da970

Please sign in to comment.