How to get a specific screen having user info of the user who logged in  ?

I am new to the OutSystems . 

I want to make an inventory app where after login, user will be redirected to his/her categories and products. 

  •   User1 login and got the category and product he/she listed previously . He/she will add or remove category or products accordingly . 
  •  User2 login and got the category and product he/she listed previously . He/she will add or remove category or products accordingly . 

This should happen to everyone who is logging in . Is this possible ?  

Hello Mayuri Pokale,

I downloaded your oml and made some changes.

There are 2 ways you can set up your database to implement your need. 

1. Assuming your products/categories have a 1 to 1 relation with your User ( only 1 User can be associated with 1 product/category ) the example that I gave you earlier will work with both of the cases. 

2.  If your  products/categories have a 1 to many type relationship ( for example more than 1 user can list the same product/category ) then you should have a table that related both of those fields like the UserCategory Entity that you have on the .oml)

With this in mind, every time that a product or category is created you must also use the Create or the CreateOrUpdate functions for the respective entity. 

Please check the attached .oml :) 

Hope it helps,

Paulo Rosário


SolutionTryDB_PR.oml

Hi Mayuri,

To do that, you need a relation between users and categories/products. I assume categories/products are general (have their own Entities in the data modal) and anyone can be related to any category/product.

In that case, you would need a many-to-many relation between Users Entity and Categories/Products, e.g. a new relation Entity like UserCategory, where you would have UserId and CategoryId as fields.

I assume another flow (screen) would fill in those records, i.e. which category belongs to whom, and that relation data is already available in DB.

So, after a user logs in, in the screen where the user is redirected, you would get the categories of that user with a Data Action. The input parameter of the action would be UserId (you can pass GetUserId(), which is a readily available function that stores the UserId of the currently logged in user), and the output of the action would be a list of categories.

In the action, you would join the UserCategory and Category entities, and filter by UserCategory.UserId = CurrentUserId, to get only the categories of the given user.

I suggest you check Modeling Data and Aggregates 101 courses in OutSystems Guided Paths, to understand more on how to build a data model.

Cheers


Thanks  Ozan Can Çalı for quick response !

It not working as expected , I am getting all categories assign to all users , so whoever is logging in getting all the category and product under that category . May be I am messed up with database creation . 

Here is what I created , attaching a snapshot . 

Database_SS.png

Hi Mayuri,

The data modal actually seems fine to me. The aggregate to get a certain user's categories should consist of Category and UserCategory entities, inner joined (Only With):


 and filtered by GetUserId():


Do you already have some records in all tables? Did you try to debug the app and see that no results are returned from the aggregate? Or maybe some errors are logged into Service Center by the platform, checking that might help.

Yes I did what you suggested , it is now  not showing any records  . Can we just erase the data from users table from system module ?  I think there are some duplicates values being entered and it may conflict with what is required .

Now I am adding the category for a user and it is not reflecting back to the main screen , IDK what is happening .

Hi Mayuri,

Can you share the project .oml file here, so that we can take a look?

I checked the oml and it actually seems to be working fine for me when I added some records: a new Category record and a new UserCategory record, which would have the Id of the Category I just added, and the Id of the User that is logged in.

Do you see any data when you check the Entities in Service Studio?


Maybe there are no UserCategory records with the UserId that is currently logged in to your app.

there are no records in UserCategory . I have some records under category . 

Could you add specific category for User1 and another category for user2 ? And after user1 log in  are you able to see user1's previously added product ? What I can do to get the result you got ? 

I think for your use case, you need to call CreateUserCategory action whenever User X 'adds a product', and pass the CategoryId that is being visited by the user, and the GetUserId() for the UserId parameter. 

I don't see any actions that adds data to UserCategory entity, thus that entity is always empty and your aggregate doesn't return a result. 

Just to try out if GetCategories entity works, you can manually add a record to UserCategory from within Service Studio (View Or Edit Data of the entity). You need a valid CategoryId and the UserId of the logged in user, though.

Hello Mayuri Pokale,

Yes, that is possible! 

For that to happen you must have a field on your categories and products for the user that listed them.

And then on your aggregates, you can filter by Id of the user that's logged in using the GetUserId() Action and only show Products or categories that the user has listed.

Hope it helps! 

Paulo Rosário


Hi Paulo Rosário ,

I tried to implement this but it is still showing all categories entered by all users . I tried to add filters too but not getting output as required . 

Hello Mayuri Pokale,

I downloaded your oml and made some changes.

There are 2 ways you can set up your database to implement your need. 

1. Assuming your products/categories have a 1 to 1 relation with your User ( only 1 User can be associated with 1 product/category ) the example that I gave you earlier will work with both of the cases. 

2.  If your  products/categories have a 1 to many type relationship ( for example more than 1 user can list the same product/category ) then you should have a table that related both of those fields like the UserCategory Entity that you have on the .oml)

With this in mind, every time that a product or category is created you must also use the Create or the CreateOrUpdate functions for the respective entity. 

Please check the attached .oml :) 

Hope it helps,

Paulo Rosário


SolutionTryDB_PR.oml

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