Pass data of Post type REST API to another screen

Pass data of Post type REST API to another screen

  

Hi,

I have a Login screen in which there is a login button. I am calling a Post type REST API on that button in which I am getting all the details of an employee. I want to map all those details in the Profile screen. How can I do that ?

Thanks.

Hi Charul,

I'd assume you just need to add some extra logic to the Screen Action that calls your REST method Action, so you'd store the output parameters somewhere... what kind of application is it, and how frequently would employee data change?

Jorge Martins wrote:

Hi Charul,

I'd assume you just need to add some extra logic to the Screen Action that calls your REST method Action, so you'd store the output parameters somewhere... what kind of application is it, and how frequently would employee data change?

Hi Jorge,

Thank for your response.

The employee data changes as there are no. of employee, say 200 approx. So at a time when a employee logins with his unique id and password, the profile screen shows all his details like name, dept, branch, Manager name and number etc. 

How can I store the API response data like in local storage or what ? And what logic should I implement on the login screen?

Thanks.


Solution

From your response and reference to Local Storage, I'd assume it's a Mobile App.

If you only want to keep the current logged in employee's data, I'd agree that you can perfectly store that in a Local Storage Entity (I'll name it LocalEmployeeProfile in the remainder of this post).

  1. First define the LocalEmployeeProfile entity in the Local Storage folder (in the Data tab).
  2. Then on the Server Action that does the REST call, return the data you obtained from API response (either as multiple output parameters or a structure you define explicitly for this purpose).
  3. Finally, on the Client Action that handles the Login button (and calls the Server Action in 2.):
    1. Create a local variable of the entity type created in 1. (in my example, LocalEmployeeProfile)
    2. After calling the Server Action from 2., assign output parameters to the respective LocalEmployeeProfile attributes
    3. Call the DeleteAllLocalEmployeeProfiles Entity Action to guarantee you will only have data for the employee that just logged in
    4. Call the CreateOrUpdateLocalEmployeeProfile Entity Action to store the employee's data on the device.
  4. Every time you need to show employee data, you just need to use an Aggregate to fetch all records of LocalEmployeeProfile (due to 3.3. above you know there will always be just one record).
Solution

Jorge Martins wrote:

From your response and reference to Local Storage, I'd assume it's a Mobile App.

If you only want to keep the current logged in employee's data, I'd agree that you can perfectly store that in a Local Storage Entity (I'll name it LocalEmployeeProfile in the remainder of this post).

  1. First define the LocalEmployeeProfile entity in the Local Storage folder (in the Data tab).
  2. Then on the Server Action that does the REST call, return the data you obtained from API response (either as multiple output parameters or a structure you define explicitly for this purpose).
  3. Finally, on the Client Action that handles the Login button (and calls the Server Action in 2.):
    1. Create a local variable of the entity type created in 1. (in my example, LocalEmployeeProfile)
    2. After calling the Server Action from 2., assign output parameters to the respective LocalEmployeeProfile attributes
    3. Call the DeleteAllLocalEmployeeProfiles Entity Action to guarantee you will only have data for the employee that just logged in
    4. Call the CreateOrUpdateLocalEmployeeProfile Entity Action to store the employee's data on the device.
  4. Every time you need to show employee data, you just need to use an Aggregate to fetch all records of LocalEmployeeProfile (due to 3.3. above you know there will always be just one record).

Hi,

I don't want to show current employee data. Whenever a employee log-ins, he should see his particular data on the profile screen. Every employee has unique Employee Id and his information we receive in the response of API on login screen. 


That is what I meant... once you login a user, you store that user's information on the device so you can display it on the profile screen.

If you managed to follow those instructions and solved your issue, please mark them as the solution, otherwise let us know what's the problem so the community can try to further help you.

Jorge Martins wrote:

That is what I meant... once you login a user, you store that user's information on the device so you can display it on the profile screen.

If you managed to follow those instructions and solved your issue, please mark them as the solution, otherwise let us know what's the problem so the community can try to further help you.

Okay. I am trying to follow the above steps. But getting problem in implementing from step 2. Kindly explain.

Can you show us the action flow of the Screen Action that handles the button? and the action flow of the Server Action that does the REST call?

Step 2. simply means that you need to add Output Parameters to the Server Action and, on its action flow, after the REST call, add an Assign tool and assign to the newly created Output Parameters the relevant REST call outputs. 

This is the action flow which is implemented on "OnLoginClick" Client Action of my login button. PostLogin is my POST type REST API. I am a beginner so I dont know the basic terms like Server Action etc. Also I am having difficulty in working with Aggregates.

Given how you've implemented things... skip my step 2. and go directly to 3.

PostLogin has outputs, right?...

  1. Finally, on the Client Action that handles the Login button (and calls the Server Action in 2.):
    1. Create a local variable of the entity type created in 1. (in my example, LocalEmployeeProfile)
    2. After calling the Server Action from 2. PostLogin REST method, assign output parameters to the respective LocalEmployeeProfile attributes
    3. Call the DeleteAllLocalEmployeeProfiles Entity Action to guarantee you will only have data for the employee that just logged in
    4. Call the CreateOrUpdateLocalEmployeeProfile Entity Action to store the employee's data on the device.
  2. Every time you need to show employee data, you just need to use an Aggregate to fetch all records of LocalEmployeeProfile (due to 3.3. above you know there will always be just one record).

If you are having difficulty working with Aggregates, I suggest you review the lessons on Retrieving Data in OutSystems from Developing OutSystems Mobile Apps.

I really don't understand the meaning of this statement of yours - "you need to add Output Parameters to the Server Action". Also, I have modified my action flow and shown you the assignments below the screen and my local variable of my entity type in the Interface Tab. Kindly refer the screenshot.

Charul,

In your Assign tool, you are assigning to the output of your PostLogin the value of Var1.Emp_name (that I'm guessing will be empty)...

...you should be assigning to Var1.Emp_name the value of PostLogin.Response.Current.Emp_name (and similar for the remainder attributes)

Jorge Martins wrote:

Charul,

In your Assign tool, you are assigning to the output of your PostLogin the value of Var1.Emp_name (that I'm guessing will be empty)...

...you should be assigning to Var1.Emp_name the value of PostLogin.Response.Current.Emp_name (and similar for the remainder attributes)

Thank you so much Jorge. You made my day !! Saved a lot of time.