nhass

Problem iterating results from GetUpdatedPackagesWithinDateRange report method

0 votes
I’m a little confused over how to correctly and completely iterate over the results returned from the esl.PackageService.GetUpdatedPackagesWithinDateRange, as it appears I’m only iterating over the first 10 items. I have the following code:
Page packages = esl.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.SENT, new PageRequest(1), startDate, endDate);

//packages has 28 TotalElements

if (packages != null && packages.TotalElements > 0)
{
	foreach (DocumentPackage dp in packages)
	{
		//processing
		
		//only doing 10 iterations
		//how to do all 28
	}
}
The above foreach loop is only executing 10 times. How do I get it to execute for all 28 elements. It is my understanding when I call the “GetUpdatedPackagesWithinDateRange” and pass the parameter “new PageRequest(1)” that ALL the results are in one page. Is this not correct? Do I need to define the PageRequest with some large pagesize parameter as well; i.e. 1000? This is a problem in our production environment, a timely response is much appreciated. Thanks

Reply to: Problem iterating results from GetUpdatedPackagesWithinDateRange report method

0 votes
Hi Nathan, You are only getting 10 packages back because "new PageRequest(1)" only retrieves the first page of packages, which is only 10. You can change the maximum number of packages retrieved by doing "new PageRequest(1, 50)", which will retrieve 50 packages in the first page (50 is the maximum you can retrieve per page). If you want to retrieve all the packages within your date range, you can do something like this:
int i = 1;
Page packages = esl.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.SENT, new PageRequest(i, 50), startDate, endDate);

if (packages != null && packages.TotalElements > 0)
{
     foreach (DocumentPackage dp in packages)
     {
          Debug.WriteLine(dp.Id);
           i++;
      }
      packages = esl.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.SENT, new PageRequest(i, 50), startDate, endDate);
} 
edit: The integer i is the index needed to keep track of the packages in the page. Let me know if you can any other questions.
Haris Haidary OneSpan Technical Consultant

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off