Skip to content

Commit 669eae0

Browse files
authored
Merge pull request #3152 from gautamdsheth/feature/2922
Feature #2922: added pagination for Add-PnPDataRowsToSiteTemplate cmdlet
2 parents e3ccb31 + 4c5f902 commit 669eae0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
4848
- Improved `Set-PnPHomePage` cmdlet to handle forward slash issue. [#3128](https://github.com/pnp/powershell/pull/3128)
4949
- Improved `Connect-PnPOnline` cmdlet to handle ping on the destination server to check if it exists. [PR](https://github.com/pnp/powershell/commit/cc3c5564fca9ce96b1a2ac47c7aabdc8b90136d0) and [#3154](https://github.com/pnp/powershell/pull/3154)
5050
- Improved `Invoke-PnPGraphMethod` cmdlet to show a better error message when sufficient permissions are not available. [#3133](https://github.com/pnp/powershell/pull/3133)
51+
- Improved `Add-PnPDataRowsToSiteTemplate` cmdlet to retrieve list item with pagination. [#3152](https://github.com/pnp/powershell/pull/3152)
5152

5253
### Removed
5354

src/Commands/Provisioning/Site/AddDataRowsToSiteTemplate.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class AddDataRowsToSiteTemplate : PnPWebCmdlet
4646

4747
[Parameter(Mandatory = false)]
4848
[ValidateNotNullOrEmpty]
49-
public string KeyColumn;
49+
public string KeyColumn;
5050

5151
private readonly static FieldType[] _unsupportedFieldTypes =
5252
{
@@ -104,11 +104,21 @@ protected override void ExecuteCmdlet()
104104
viewFieldsStringBuilder.Append("</ViewFields>");
105105
}
106106

107-
query.ViewXml = string.Format("<View>{0}{1}</View>", Query, viewFieldsStringBuilder);
108-
var listItems = spList.GetItems(query);
107+
query.ViewXml = string.Format("<View Scope='RecursiveAll'>{0}{1}</View>", Query, viewFieldsStringBuilder);
108+
List<ListItem> listItems = new List<ListItem>();
109+
do
110+
{
111+
var listItemsCollection = spList.GetItems(query);
109112

110-
ClientContext.Load(listItems, lI => lI.Include(l => l.HasUniqueRoleAssignments, l => l.ContentType.StringId));
111-
ClientContext.ExecuteQueryRetry();
113+
ClientContext.Load(listItemsCollection, lI => lI.Include(l => l.HasUniqueRoleAssignments, l => l.ContentType.StringId));
114+
ClientContext.ExecuteQueryRetry();
115+
116+
listItemsCollection.EnsureProperty(l => l.ListItemCollectionPosition);
117+
118+
query.ListItemCollectionPosition = listItemsCollection.ListItemCollectionPosition;
119+
listItems.AddRange(listItemsCollection);
120+
121+
} while (query.ListItemCollectionPosition != null);
112122

113123
Microsoft.SharePoint.Client.FieldCollection fieldCollection = spList.Fields;
114124
ClientContext.Load(fieldCollection, fs => fs.Include(f => f.InternalName, f => f.FieldTypeKind, f => f.ReadOnlyField));

0 commit comments

Comments
 (0)