-
Notifications
You must be signed in to change notification settings - Fork 289
Pagination for microsoft graph module #3940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JesperSchulz
merged 12 commits into
microsoft:main
from
Drakonian:PaginationForMicrosoftGraphModule
Aug 20, 2025
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
16ac57e
Pagination support for MicrosoftGraph module
Drakonian 05263cb
Merge remote-tracking branch 'origin/main' into PaginationForMicrosof…
Drakonian 2400cff
Merge remote-tracking branch 'origin/main' into PaginationForMicrosof…
Drakonian f878aea
Merge remote-tracking branch 'origin/main' into PaginationForMicrosof…
Drakonian da2f6c8
Merge remote-tracking branch 'origin/main' into PaginationForMicrosof…
Drakonian 19cf4fa
Return last HttpResponseMessage in GetAllPages for diagnosis
Drakonian abfb1c9
Merge remote-tracking branch 'origin/main' into PaginationForMicrosof…
Drakonian fa8de3c
Tests: Replace AreEqual method to IsTrue/IsFale for boolean values
Drakonian 2bc6378
Add internals visible to graph test app
Drakonian a640f2f
Fix tiny typo
JesperSchulz 1ae3c9d
Replace underscore with this. for global variables
Drakonian a3b0328
Merge branch 'PaginationForMicrosoftGraphModule' of https://github.co…
Drakonian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ | |
| "idRanges": [ | ||
| { | ||
| "from": 9350, | ||
| "to": 9359 | ||
| "to": 9361 | ||
| } | ||
| ], | ||
| "target": "OnPrem", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/System Application/App/MicrosoftGraph/src/GraphPaginationData.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
| namespace System.Integration.Graph; | ||
|
|
||
| /// <summary> | ||
| /// Holder for pagination data when working with Microsoft Graph API responses. | ||
| /// </summary> | ||
| codeunit 9360 "Graph Pagination Data" | ||
| { | ||
| Access = Public; | ||
| InherentEntitlements = X; | ||
| InherentPermissions = X; | ||
|
|
||
| var | ||
| GraphPaginationDataImpl: Codeunit "Graph Pagination Data Impl."; | ||
|
|
||
Drakonian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <summary> | ||
| /// Sets the next link URL for retrieving the next page of results. | ||
| /// </summary> | ||
| /// <param name="NewNextLink">The @odata.nextLink value from the Graph response.</param> | ||
| procedure SetNextLink(NewNextLink: Text) | ||
| begin | ||
| GraphPaginationDataImpl.SetNextLink(NewNextLink); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Gets the current next link URL. | ||
| /// </summary> | ||
| /// <returns>The URL to retrieve the next page of results.</returns> | ||
| procedure GetNextLink(): Text | ||
| begin | ||
| exit(GraphPaginationDataImpl.GetNextLink()); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Checks if there are more pages available. | ||
| /// </summary> | ||
| /// <returns>True if more pages are available; otherwise false.</returns> | ||
| procedure HasMorePages(): Boolean | ||
| begin | ||
| exit(GraphPaginationDataImpl.HasMorePages()); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Sets the page size for pagination requests. | ||
| /// </summary> | ||
| /// <param name="NewPageSize">The number of items to retrieve per page (max 999).</param> | ||
| procedure SetPageSize(NewPageSize: Integer) | ||
| begin | ||
| GraphPaginationDataImpl.SetPageSize(NewPageSize); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Gets the current page size. | ||
| /// </summary> | ||
| /// <returns>The number of items per page.</returns> | ||
| procedure GetPageSize(): Integer | ||
| begin | ||
| exit(GraphPaginationDataImpl.GetPageSize()); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Gets the default page size. | ||
| /// </summary> | ||
| /// <returns>The default number of items per page.</returns> | ||
| procedure GetDefaultPageSize(): Integer | ||
| begin | ||
| exit(GraphPaginationDataImpl.GetDefaultPageSize()); | ||
| end; | ||
|
|
||
| /// <summary> | ||
| /// Resets the pagination data to initial state. | ||
| /// </summary> | ||
| procedure Reset() | ||
| begin | ||
| GraphPaginationDataImpl.Reset(); | ||
| end; | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
src/System Application/App/MicrosoftGraph/src/GraphPaginationDataImpl.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
| namespace System.Integration.Graph; | ||
|
|
||
| codeunit 9361 "Graph Pagination Data Impl." | ||
| { | ||
| Access = Internal; | ||
| InherentEntitlements = X; | ||
| InherentPermissions = X; | ||
|
|
||
| var | ||
| NextLink: Text; | ||
| PageSize: Integer; | ||
| DefaultPageSizeErr: Label 'Page size must be between 1 and 999.'; | ||
|
|
||
| procedure SetNextLink(NewNextLink: Text) | ||
| begin | ||
| NextLink := NewNextLink; | ||
| end; | ||
|
|
||
| procedure GetNextLink(): Text | ||
| begin | ||
| exit(NextLink); | ||
| end; | ||
|
|
||
| procedure HasMorePages(): Boolean | ||
| begin | ||
| exit(NextLink <> ''); | ||
| end; | ||
|
|
||
| procedure SetPageSize(NewPageSize: Integer) | ||
| begin | ||
| if not (NewPageSize in [1 .. 999]) then | ||
| Error(DefaultPageSizeErr); | ||
|
|
||
| PageSize := NewPageSize; | ||
| end; | ||
|
|
||
| procedure GetPageSize(): Integer | ||
| begin | ||
| if PageSize = 0 then | ||
| exit(GetDefaultPageSize()); | ||
|
|
||
| exit(PageSize); | ||
| end; | ||
|
|
||
| procedure Reset() | ||
| begin | ||
| Clear(NextLink); | ||
| Clear(PageSize); | ||
| end; | ||
|
|
||
| procedure GetDefaultPageSize(): Integer | ||
| begin | ||
| exit(100); | ||
| end; | ||
| } |
101 changes: 101 additions & 0 deletions
101
src/System Application/App/MicrosoftGraph/src/helper/GraphPaginationHelper.Codeunit.al
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
| namespace System.Integration.Graph; | ||
|
|
||
| using System.RestClient; | ||
|
|
||
| codeunit 9359 "Graph Pagination Helper" | ||
| { | ||
| Access = Internal; | ||
| InherentEntitlements = X; | ||
| InherentPermissions = X; | ||
|
|
||
| procedure ExtractNextLink(HttpResponseMessage: Codeunit "Http Response Message"; var GraphPaginationData: Codeunit "Graph Pagination Data") | ||
| var | ||
| ResponseJson: JsonObject; | ||
| JsonToken: JsonToken; | ||
| NextLink: Text; | ||
| ResponseText: Text; | ||
| begin | ||
| if not HttpResponseMessage.GetIsSuccessStatusCode() then begin | ||
| GraphPaginationData.SetNextLink(''); | ||
| exit; | ||
| end; | ||
|
|
||
| ResponseText := HttpResponseMessage.GetContent().AsText(); | ||
|
|
||
| // Parse JSON response | ||
| if not ResponseJson.ReadFrom(ResponseText) then begin | ||
| GraphPaginationData.SetNextLink(''); | ||
| exit; | ||
| end; | ||
|
|
||
| // Extract nextLink | ||
| if ResponseJson.Get('@odata.nextLink', JsonToken) then | ||
| NextLink := JsonToken.AsValue().AsText(); | ||
|
|
||
| GraphPaginationData.SetNextLink(NextLink); | ||
| end; | ||
|
|
||
| procedure ExtractValueArray(HttpResponseMessage: Codeunit "Http Response Message"; var ValueArray: JsonArray): Boolean | ||
| var | ||
| ResponseJson: JsonObject; | ||
| JsonToken: JsonToken; | ||
| ResponseText: Text; | ||
| begin | ||
| Clear(ValueArray); | ||
|
|
||
| if not HttpResponseMessage.GetIsSuccessStatusCode() then | ||
| exit(false); | ||
|
|
||
| ResponseText := HttpResponseMessage.GetContent().AsText(); | ||
|
|
||
| // Parse JSON response | ||
| if not ResponseJson.ReadFrom(ResponseText) then | ||
| exit(false); | ||
|
|
||
| // Extract value array | ||
| if not ResponseJson.Get('value', JsonToken) then | ||
| exit(false); | ||
|
|
||
| ValueArray := JsonToken.AsArray(); | ||
| exit(true); | ||
| end; | ||
|
|
||
| procedure ApplyPageSize(var GraphOptionalParameters: Codeunit "Graph Optional Parameters"; GraphPaginationData: Codeunit "Graph Pagination Data") | ||
| begin | ||
| if GraphPaginationData.GetPageSize() > 0 then | ||
| GraphOptionalParameters.SetODataQueryParameter(Enum::"Graph OData Query Parameter"::top, Format(GraphPaginationData.GetPageSize())); | ||
| end; | ||
|
|
||
| procedure CombineValueArrays(HttpResponseMessage: Codeunit "Http Response Message"; var JsonResults: JsonArray): Boolean | ||
| var | ||
| ValueArray: JsonArray; | ||
| JsonItem: JsonToken; | ||
| begin | ||
| if not ExtractValueArray(HttpResponseMessage, ValueArray) then | ||
| exit(false); | ||
|
|
||
| foreach JsonItem in ValueArray do | ||
| JsonResults.Add(JsonItem); | ||
|
|
||
| exit(true); | ||
| end; | ||
|
|
||
| procedure IsWithinIterationLimit(var IterationCount: Integer; MaxIterations: Integer): Boolean | ||
| begin | ||
| if IterationCount >= MaxIterations then | ||
| exit(false); | ||
|
|
||
| IterationCount += 1; | ||
|
|
||
| exit(true); | ||
| end; | ||
|
|
||
| procedure GetMaxIterations(): Integer | ||
| begin | ||
| exit(1000); // Safety limit to prevent infinite loops | ||
| end; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.