Reconcile open purchase orders across pages¶
Use this workflow to retrieve every page of open purchase orders and compare the results with supplier information. Put pagination in a published child workflow so other workflows can reuse it.
Before you begin¶
Choose a read-only order operation that supports supplier filtering and cursor pagination. This example uses an items array and a nextCursor string that is empty or null on the last page. Adapt the expressions to your operation’s response shape.
Workflow flow¶
flowchart TD
subgraph Parent["Parent reconciliation workflow"]
ParentStart([Webhook receives supplierNumber]) --> Parallel["Parallel · Run both lookups"]
Parallel --> Call["Workflow · Call the published child"]
Parallel --> Profile["Business Object Function · Read the supplier profile"]
Call --> Join["Code · Check both results and count the orders"]
Profile --> Join
Join --> ParentResult([Return supplier, order count, and completeness])
end
subgraph Child["Child pagination workflow"]
ChildStart([Receive supplierNumber]) --> Init["Set Variables · Initialize pagination"]
Init --> Loop{"While Loop · More pages and fewer than 10 read?"}
Loop -->|Yes| Page["External REST · Read the next page"]
Page --> Check["Code · Combine items and check the next cursor"]
Check -->|Cursor repeated| Error([Handle the pagination error])
Check -->|Continue| Save["Set Variables · Save orders and pagination state"]
Save --> Loop
Loop -->|No| ChildResult([Return accumulated orders and completeness])
end
Call -.-> ChildStart
ChildResult -.-> Call
Configure the workflows¶
Configure the child workflow¶
- Child inputs and state. Define a String webhook input named
supplierNumber. Use Set Variables to initialize Array variablesordersandseenCursorsto[], the Stringcursorto an empty string, the BooleanhasMoreto true, and the IntegerpagesReadto0. - While Loop. Set While Condition to
{{$context.$variables.hasMore && $context.$variables.pagesRead < 10}}. In the loop body, add an External REST node namedREAD_ORDER_PAGE. Map the supplier number from the webhook and the cursor from{{$context.$variables.cursor}}. Follow the endpoint's first-page convention when no cursor is available. - Evaluate the page and update state. In a Code node, combine
orderswith{{$context.$nodes.READ_ORDER_PAGE.$output.items}}. Check the returnednextCursoragainstseenCursors. Route a repeated cursor to the error path. Otherwise, use Set Variables to save the combined array, the next cursor, the list of nonempty cursors seen so far, the updatedhasMoreflag, and the incremented page count. - Child Return. Return the accumulated orders and a Boolean
completethat is true only when the endpoint reports no next page. If the limit is reached with another page available, returncomplete: falseso the parent can identify a partial result. Publish the child workflow.
Configure the parent workflow¶
- Parent Parallel. Define the same supplier input in the parent. In one Parallel branch, add a Workflow node named
GET_OPEN_ORDERS. Select the published child and mapsupplierNumberto{{$context.$triggers.REST.$input.supplierNumber}}. In the other branch, use a Business Object Function namedGET_SUPPLIERto retrieve the supplier profile by number. Neither branch needs output from the other. - Parent Code and Return. After both branches finish, read the child's business result from
{{$context.$nodes.GET_OPEN_ORDERS.$output.output}}and the supplier profile from{{$context.$nodes.GET_SUPPLIER.$output}}. If the child's result is a JSON string, parse it in the Code node before reading its fields. Validate both branch results before counting the orders. Route a failed, missing, or unreadable result to the error path. Return the supplier number, open-order count, and completeness flag.
Run the reconciliation workflow¶
Use a test supplier whose order search returns two pages containing a total of three open orders.
Sample parent request
{
"invocationMode": "END_USER",
"message": "Count open purchase orders.",
"parameters": {
"supplierNumber": "8057"
}
}
Sample workflow output
Expected behavior¶
| Scenario | Expected behavior |
|---|---|
| Two pages with three orders overall | The child stops when no cursor remains. The parent returns 3 with complete: true. |
| No orders | The result is 0 with complete: true. |
| Cursor repeats | The child takes the error path instead of requesting the same page again. |
| Another page exists after the tenth page | The parent reports complete: false with the partial count. |
| Either parallel branch fails | The workflow reports the failed result without presenting a successful reconciliation. |
Related guides
Workflow · While Loop · Parallel · Set Variables