6241
Views
13
Comments
Retrieving the current user that is logged in
Question

Hi guys i would like to retrieve the current user that is logged in as the main page. Example after the user login i would like to have a page "Welcome User1" The screenshot below shows the the variables that i have fetched from the database but i am not sure if this is the correct way to do it. Please advice me thanks

2019-01-04 10-45-45
Sravan Vanteru

Hi Koalified,

Follow below steps.

1. Outsystems has built in function to get current logged in user id ( BuiltFunctions -> Roles -> GetUserId() )

2. Use GetUser function in Preparation to get user details and use them in web screen.


Hope this helps.

Sravan

UserImage.jpg
Koalified

Sravan Vanteru wrote:

Hi Koalified,

Follow below steps.

1. Outsystems has built in function to get current logged in user id ( BuiltFunctions -> Roles -> GetUserId() )

2. Use GetUser function in Preparation to get user details and use them in web screen.


Hope this helps.

Sravan


Hi i would like to ask is it possible to use "Username" as a primary key to another database ?

2022-08-22 10-34-02
Padmakumar Chendrani


"Hi " + GetUser(GetUserId()).User.Name+ " ,Welcome to " + GetAppName() + "."

You can try with the above expression. You will get a result like below. (Ignore the icon, of course)


2020-02-28 09-46-54
Eduardo Jauch

Hello Koalified.

1. It is better to use an aggregate filtered by the UserId against GetUserId(), than to use GetUser function, because the former will be optimized.

2. If it is an external database, in it you can use whatever you like and it is allowed. But you should have in mind that the attribute UserName in entity User is not "unique", so you can have problems if you don't pay attention to this detail. 

Why don't you use the user id? There is any reason?

Cheers.

2020-02-28 09-46-54
Eduardo Jauch

P.S. You can't change the User entity in any way, as it is a System entity.

But you can extend it creating an extension entity, that is a new entity where the Identifier data type will be "User Identifier" (PK and FK at the same time) that will create a 1:1 relationship between them.

UserImage.jpg
Koalified

Eduardo Jauch wrote:

P.S. You can't change the User entity in any way, as it is a System entity.

But you can extend it creating an extension entity, that is a new entity where the Identifier data type will be "User Identifier" (PK and FK at the same time) that will create a 1:1 relationship between them.

Hi how i did was this

So i would like to "link" sheet1 to user in the system... So how do i "link" them?

2020-02-28 09-46-54
Eduardo Jauch

I think you already did through the UserId FK on the Sheet1...
It is not a User Identifier data type?

Cheers.

UserImage.jpg
Koalified

Eduardo Jauch wrote:

I think you already did through the UserId FK on the Sheet1...
It is not a User Identifier data type?

Cheers.


it is unique but not used to link both data together...

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Koalified,

Be aware that you are querying Server Entities, not Local ones, which means that you are making a call to the Server, which may slow things down. I'd advise you to cache the currently logged in user name in case you need it more often.

UserImage.jpg
Koalified

Kilian Hekhuis wrote:

Hi Koalified,

Be aware that you are querying Server Entities, not Local ones, which means that you are making a call to the Server, which may slow things down. I'd advise you to cache the currently logged in user name in case you need it more often.


Hi what do you mean by cache? Is there examples?

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

With "cache" I mean store it locally, in a Local Entity.

2020-10-28 09-51-07
Felipe Santos

thanks for sharing

2020-11-15 18-11-47
Stephen Scarfo

i am looking to do something similar, but your example seems incomplete to me. I have the built in UserID and a Role Based ID. I need to put them together so when i query the database i can get both the logged in UserID and the ID of that unique role. 

i.e. UserID: 59 and TalentID: 11

I can always get UserID with the built in function. I need to tie the TalentID to that users profile. 

The Goal is: Have a logged in user be able to see anyones profile, but only edit their own profile. My intention is to use this  UserID & TalentID combination as the combined key for that activity.   i.e. if the user is the logged in user and the profile they are viewing is their own then they can edit, but otherwise they can only view. etc.....

I'm fairly new in outsystems so any explicit steps you have are appreciated. 


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