For Each Loop to build table detail using REST calls

For Each Loop to build table detail using REST calls

  

The challenge I have is using REST calls to populate a web app table.

I am making a REST call to return the id's of all the object to put in my table (GetChildren). This successfully returns a list of items.

My plan was to take each id in a foreach loop and make a new REST call (GetProducts) to return the detail.

This plan fails because I cannot map data from the "For Each" loop into my table.

I think something is wrong with my strategy here, can anyone advise how to go about this. I'm not seeing this from the documentation as dealing with REST calls seems to be a special scenario. Ultimately the table is expecting a list.

This is like doing a database table join but I am in a REST environment. I can confirm the REST calls are working fine.

Any thoughts appreciated and I apologize if this is a simple issue but I am an OutSystems "newbie".

Hello Simon,

I'm assuming that this is not a 'nested' scenario, right? 

The first problem you will face is related to performance... Imagine you retrieve 30 ID. You will have to make 30 requests...

So, first thing. The API wouldn't have a method to return the Id AND the Detail in the same request?

Second, maybe this could be a scenario for keep data locally and you do some synchronization to keep the data up to date instead of a real time connection. If this is possible for your use case, I would adopt it.

In the end, the way you are doing it now, you need to have a local list, which will be the source of your table records, base on an structure will all the data you need.

You create an entry for each id, and than in your looping, do the request and fill the information of the detail. 

Now your list is finished and the table records will show the info.

Cheers

Eduardo Jauch wrote:

Hello Simon,

I'm assuming that this is not a 'nested' scenario, right? 

The first problem you will face is related to performance... Imagine you retrieve 30 ID. You will have to make 30 requests...

So, first thing. The API wouldn't have a method to return the Id AND the Detail in the same request?

Second, maybe this could be a scenario for keep data locally and you do some synchronization to keep the data up to date instead of a real time connection. If this is possible for your use case, I would adopt it.

In the end, the way you are doing it now, you need to have a local list, which will be the source of your table records, base on an structure will all the data you need.

You create an entry for each id, and than in your looping, do the request and fill the information of the detail. 

Now your list is finished and the table records will show the info.

Cheers

Thanks Eduardo,

Your comments about performance are absolutely right. Right now this approach will be fine, enhancing my APIs will come once I've proven the use case. I'll research creating local lists.


Regarding the lists...

Create a structure that will hold your data.

Add a local variable to the page, whose type is a list of that structure.

Craate a variable of the structure type.

For each item, fill the variable with the correct values and use the ListAppend to add to the list variable.

Basically this.

Cheers.