Assigning API response to List Local Variable and to use and refresh on Table Records

Hello everyone. I’d like to start my first thread by greeting you all with excitement. I applied for a nocode/lowcode job and now given an assignment. I am junior-ish developer and took sometime to familiarize myself with the OutSystems environment by following the intro courses.

The assignment asks me to develop a simple dashboard application using OutSystems and in general task objectives consist of calling REST API, manipulating respond data and displaying them on widgets. The dashboard screen has three main elements pictured in the wireframe below:

1. Current office weather conditions
2. Employee list for this office with their “at desk” status
3. Weather forecast graph


I fetch the data from REST, assign the response to Data Action output which is defined Employee List type. Selecting this Data Action Output for Table source, I’ve managed to successfully display the data on Table however it shows empty for the local variable list I created by encapsulating some logic to save the outcome of the same response. As the API data type is not list, I realized I need to use ListAppend server action and foreach to assign each member of the array as member of list.

Logic1

Logic 2

#1 Could someone please help me with the correcting the mistake in action logics so that list getting entirely filled. In expression it prints the length of EmpList is 1. In case logic is correct then why list has just 1 element?

#2 I intend to use DropDown list for office locations and update table and weather information accordingly. To refresh data in Table record , I found this solution by a member useful. However could someone help me explaining little more about the 4th step so that I could implement please?

https://www.outsystems.com/forums/discussion/39318/how-to-use-refresh-data-on-a-list-of-record/

The Refresh Data tool only works for queries (Aggregates or SQL).

If your data source is the output of a server action, you will need to call it again on the screen action. You accomplish this following these steps:

  1. Create a Local Variable on your Screen (I'll call it ActionOutput);
  2. On the Preparation, after calling your server action assign it's output to the ActionOutput local variable;
  3. On your Screen, use the ActionOutput local variable as the Source Record List of your TableRecords/ListRecords widget instead of directly the output of your server action from the Preparation;
  4. On the Screen Action, instead of the Refresh Data you were trying to use, execute your action again, assign it's output to the ActionOutput local variable, and Ajax Refresh the TableRecords/ListRecords

Many thanks in advance ! 

Attached you can find my project file for your convenience to look at easily.
Many thanks!

developerassignment_v43.oml

mvp_badge
MVP
Solution

Hi Gulbala,


Welcome to the OutSystems community.


One of the things I notice in your code is the misuse of the Current. Current is used in iterators or in the list to refer to the current row you are iterating. So when you use it like in the example below, you are only assigning one record, hence your mistake #1:

So, what I suggest doing is, instead of creating a lot of local variables set the outputs on your DataAction, like this:


Here, you will have one list with all the records, one filtered (which since it starts without filters, it is the same as the complete, and a list of locations - I do a ListDistinct so the list, which will populate the dropdown, does not contain duplicate records).


Regarding problem #2, it is referring to Traditional Web applications and you are working on a Reactive one.

I would suggest to, continuing the steps, I described in #1, to have a dropdown with the LocationList, binded to a Location local variable that will hold the selected value. This dropdown should have an action on the OnChange, so it can trigger the filter of the list:

The action then is as simple as filtering the complete list by the selected location and assigning the value to the FilteredList.



I am attaching the OML with the steps, although I didn't have time to test it...


Kind Regards,
João

developerassignment_v43.oml

Dear @João Marques thank you very much for your reply. Your advise to avoid local variables and instead set several outputs within an action seem to be handy. Besides setting multiple variables-values pairs within single assignment is a new approach for me that I haven’t seen in tutorial videos so I am definitely looking forward to practising it :)

Regarding 1st issue, unfortunately the problem still persists. I’ve spent several hours on it and managed to create a list however all list members are the first index element when I print them on table, i.e. it prints 50 elements from first index. In theory I understand what you mean however I can’t seem to figure out what I implement wrong. List should be type of Employee, and matching element coming from response to be added list is classified under Current only that system accepts. I’ve also noticed your action outcome -

TestCallAppendList2Emp.EmployeeListComplete

produce same result that I see in your attached project file .

I’d like to leverage OutSystems features without going back traditional programming approaches like where you deserialize json response by yourself, create custom objects, loop through it and assign variables..

I’d greatly appreciate if you could kindly write me a logic in oml file for this particular need too that will work and assign all index members! That means a lot. Thank you for taking time and your help again :)

Hello guys, I debuged the action Joao shared and the lists elements in action outputs seem to be identically filled from API response. However table displays only the first element of the list 50 times repeatedly . Any idea how to solve the issue? Thanks!

Hi all. Apparently the problem was with server and it took time for it to reflect the changes on pages. After several refresh the page came out with correct output :)
And many thanks @João Marques for your help :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.