19
Views
1
Comments
Solved
Save the logged user to the database

Hi,

I created an input to register the user who is logged in.


I created a filter in my query with the expression:

User.Username = Client.Username

Saved and I return to the previous screen...


Now whenever I change a user, it also changes in the table. It does not keep the user previously saved.

I think my expression in the table is wrong. 

Trocasv1.6.2.oml

Rank: #86
Solution

Hello there SpiritFox,

So it seems that your field Registo is associated to a specific Troca, right? In that case, you should create this new attribute in your Trocas entity (as you did for the rest of the fields). This will allow you to save the field for each Troca :)

Call it, for example, RegistadoPor (User Identifier):

In TrocaDetail screen, there is no need to execute GetUsersLogin query since you are filtering this Aggregate by:

User.Username = Client.Username

And after you're just using GetUsersLogin.List.Current.User.Username in the field. So you may just use Client.Username directly (there is no need to execute the Aggregate). Also, if this is an automatic field, I think it shouldn't be editable, so you might want to disable it:


Right before you save this Troca record in the database (when calling TrocasCreateOrUpdate Server Action), you should place an Assign to fill this RegistadoPor attribute, since it is not coming from the Form.

Since you want to register the identifier of the logged user, you may use GetUserId() function that returns exactly this information:


Back to Trocas screen (List), you should do the last join with User entity like you did to the others:


Finally, about the Expression in the table, you just need to bind it to the correct value:

GetTrocaById.List.Current.UserLogin.Name


Please refer to attached OML file with these changes.


Hope that this helps you!


Kind regards,

Rui Barradas

Trocasv1.6.2.oml