Mobile App: How do I simply display current user's name or username?

Mobile App: How do I simply display current user's name or username?

  

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

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


Solution

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


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.


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!


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.

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.

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 ;)


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. 

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.