Hello,

Outsystems newbie here. I've been researching the following issue for the past couple hours but have not had much success. Apologies in advance if this is something that has been addressed elsewhere in the forum. 

I'm trying to filter bootstrapped data by login username. I currently have the entity data placed in a blank screen so it just looks like a table. What I'd like to do is once the user completes login, have this data filter by said username and only display that data. The data itself contains an attribute that = username so in essence i'd like to achieve the excel equivalent of filtering by username and having the rest of the data also filter.


How can I go about doing this?






Hi Edwin,

You van get the username of the logged in user with: 

GetUser(GetUserId()).User.Username

With that you can filter on username. 

Does this help you?

Solution

Hi, Edwin.

Does the user have access to the screen without being logged in? Or do you need to be logged in to access it?

If you need it logged in, you just need to put the following filter in your aggregate: 

YourEntity.Username = GetUser(GetUserId()).User.Username

If you don't need to be logged in, use:

If(GerUserId ()=NullIdentifier(),YourEntity.Username<>"",YourEntity.Username=GetUser(GetUserId()).User.Username)

If you are using reactive mode, you can save the username in a Client variable in login.And you can use that variable in the aggregate filter.

But I suggest that you change the attribute in your entity from Username to UserId. To follow a best practice.

Solution

Thank you both for your prompt replies!  Let me go ahead make an attempt at both.


Hi, 

If you want and to make it more similar to sql, you can drag the user entity in the source of aggregate, join it with you bootstrap data (join condition must be user. Username = your data. Username), the join must be "only with" and in the filters just need to put "user. Id = GetUserId()". This is more common because in this way you save one roundtrip to the database to get the username. 


Best regards, 

Ricardo

Thank you all. Learned from your suggestions!

It took me a while to figure how to use the aggregate vs. the entity dragged into a table. Quick question - what's the difference between creating an aggregate through Server Actions vs. directly in the screen?

Appreciate all of your responses!


Hi,


If you create an aggregate through server action you gain ability to reuse, but, the platform can't no longer infer the fields that you need, so you loose performance. It's a trade off that you need to evaluate. (ability to reuse vs performance). 


Best regards,

Ricardo M Pereira

Eduardo S Sales Rodrigues wrote:

Hi, Edwin.

Does the user have access to the screen without being logged in? Or do you need to be logged in to access it?

If you need it logged in, you just need to put the following filter in your aggregate: 

YourEntity.Username = GetUser(GetUserId()).User.Username

If you don't need to be logged in, use:

If(GerUserId ()=NullIdentifier(),YourEntity.Username<>"",YourEntity.Username=GetUser(GetUserId()).User.Username)

If you are using reactive mode, you can save the username in a Client variable in login.And you can use that variable in the aggregate filter.

But I suggest that you change the attribute in your entity from Username to UserId. To follow a best practice.

Hi Eduardo - Would you breaking down the right part of the equation? 

GetUser(GetUserId()).User.Username --> 

In trying to understand the breakdown of the above argument , I came across this action : 

SyntaxEditor Code Snippet

User_GetName()

I set this in place of the above and it worked. Is there down side to this?