Post Closed
2063
Views
9
Comments
Solved
Mobile App: How do I simply display current user's name or username?
Question

I have a super simple mobile app that has "Users" as the User Provider Module


How do I simply show the current logged in user's name or username in an expression? I know there's a "GetUserId()" function but I can't find anything that lets you get any basic profile info

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP
Solution

Hi Brian,

You could use server actions of the User Api like the User_GetName()

  1. Set a depencency to User_GetName() from the Users Producer (Ctrl+Q)
  2. Create a Fetch data from other source on your mobile screen
  3. Set the output parameter to the value of User_GetName()
  4. Use the GetLoggedInUserName() in you screen in an expression.


Another way would be to add a Fetch data from database to your screen and an aggregate on the Users entity with a filter Users.Id = GetUserId()

Good luck with it.

Regards,

Daniel


UserImage.jpg
Aloysius Lee

Daniël Kuhlmann wrote:

Hi Brian,

You could use server actions of the User Api like the User_GetName()

  1. Set a depencency to User_GetName() from the Users Producer (Ctrl+Q)
  2. Create a Fetch data from other source on your mobile screen
  3. Set the output parameter to the value of User_GetName()
  4. Use the GetLoggedInUserName() in you screen in an expression.


Another way would be to add a Fetch data from database to your screen and an aggregate on the Users entity with a filter Users.Id = GetUserId()

Good luck with it.

Regards,

Daniel


Hi Daniel,


I tried this but i still faced with some difficulties in making it work. Are you able to do a step by step? Thanks


Regards,

Aloysius


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

Aloysius Lee wrote:

Daniël Kuhlmann wrote:

Hi Brian,

You could use server actions of the User Api like the User_GetName()

  1. Set a depencency to User_GetName() from the Users Producer (Ctrl+Q)
  2. Create a Fetch data from other source on your mobile screen
  3. Set the output parameter to the value of User_GetName()
  4. Use the GetLoggedInUserName() in you screen in an expression.


Another way would be to add a Fetch data from database to your screen and an aggregate on the Users entity with a filter Users.Id = GetUserId()

Good luck with it.

Regards,

Daniel


Hi Daniel,


I tried this but i still faced with some difficulties in making it work. Are you able to do a step by step? Thanks


Regards,

Aloysius


Daniel just did it.

In which part are you strugling?

Cheers.


UserImage.jpg
Aloysius Lee

Eduardo Jauch wrote:

Aloysius Lee wrote:

Daniël Kuhlmann wrote:

Hi Brian,

You could use server actions of the User Api like the User_GetName()

  1. Set a depencency to User_GetName() from the Users Producer (Ctrl+Q)
  2. Create a Fetch data from other source on your mobile screen
  3. Set the output parameter to the value of User_GetName()
  4. Use the GetLoggedInUserName() in you screen in an expression.


Another way would be to add a Fetch data from database to your screen and an aggregate on the Users entity with a filter Users.Id = GetUserId()

Good luck with it.

Regards,

Daniel


Hi Daniel,


I tried this but i still faced with some difficulties in making it work. Are you able to do a step by step? Thanks


Regards,

Aloysius


Daniel just did it.

In which part are you strugling?

Cheers.


Greeting


I'm constantly getting an error for keying User_GetName() in the output parameter.


Could you kindly elaborate on how to do Step 1 and Step 2?


Thanks!


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

Hello,

You need a reference to this function.
So, you have to open the Manage Dependencies dialog (crtl+Q), select Users module in the left panel and select the users' module actions you need from the right panel. Click Ok, and now you have a reference to it.

As this is a server action, in order to use it you need to call it from a server action. So, in the page where you need the user's name, add a Data Action to the screen (through the context menu of the page) and call it from there.

Cheers.

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

Note that the above will only work if you are on-line. If you want to build an app that can also work off-line, you need to cache the username in a local entity.

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

Kilian Hekhuis wrote:

Note that the above will only work if you are on-line. If you want to build an app that can also work off-line, you need to cache the username in a local entity.

Because those are "server actions" and you can't call a server action if offline ;)


UserImage.jpg
Bilal Iqbal

Dear All,


I am using this GetUserName method, and it is returning value. But I need logged in User Id e.g.


My User Id is "User123", Display Name "Daniel"....


I need "User123", where as user name function return me "Daniel", There is a function called GetUserId() but it returns internal key value like 23.


Can you please advise for it. 

2019-09-24 18-41-25
Jorge Martins
 
MVP

Hi Bilal Iqbal,

You need the user to provide you with the Username to login, right? I advise you to follow Killian's suggestion and as soon as you successfully login cache that Username in a Local Storage Entity. That way you can easily read it from Local Storage. Be sure to clean up that cache upon logout though.