Skip to main content

For Each - Parent/Child

If you need to call the API multiple times based on the results of a call you can use the ForEach function to loop over the results.

In the example below a list of suppliers is returned and then a list of products are returned for each supplier whilst still using a paging request.

<Fetch url="{URL}/app/list/suppliers">
<!-- For Each SupplierID get the related Products -->
<ForEach path="data">
<!-- Handle Paging for the Product List -->
<PagingRequest path="data" start="1" next-path="nextpage">
<Fetch url="{URL}/app/list/products?filter=SupplierID%20eq%20{$SupplierID}&amp;page={PagingRequest.Page}">
<DataTableTransform path="data" />
</Fetch>
</PagingRequest>
</ForEach>
</Fetch>

You can also use the ForEach function when doing the schema discovery, like below:

<Action name="GetDataSchema">
<Fetch url="{URL}/app/list/{Datasource.Name}/Schema">
<ForEach path="Columns">
<Column name="$Name" data-type="$DataType" allow-null="$AllowNull" length="$MaxLength" unique="$Unique" />
</ForEach>
</Fetch>
</Action>