Display Current user - username

Hello my objective is to save current user username to display it latter in a web app (saving it into a variable )

Iam logging in my mobile app and i want to know the username of the people that is currently on  and save it in a variable in my database any ideas ?

Cheers

Hi David


GetUser(GetUserId()).User.Name


Or in the username case


GetUser(GetUserId()).User.Username


Hope it helps.

Hugo Duarte wrote:

Hi David


GetUser(GetUserId()).User.Name


Hey then assign it with the variable i want to store it into ? 

David Fernandes wrote:

Hugo Duarte wrote:

Hi David


GetUser(GetUserId()).User.Name


Hey then assign it with the variable i want to store it into ? 


Exactly you can assign it on whatever you want.


Hugo Duarte wrote:

David Fernandes wrote:

Hugo Duarte wrote:

Hi David


GetUser(GetUserId()).User.Name


Hey then assign it with the variable i want to store it into ? 


Exactly you can assign it on whatever you want.



Having this small problem 

You need to reference the entity User from system. 


Go to manage dependancies > system > user. 

Hugo Duarte wrote:

You need to reference the entity User from system. 


Go to manage dependancies > system > user. 

i just did that and still giving me error at this variable at assign 

GetUser(GetUserId()).User.Name

Cant find Get user function in expression


Hi David,

As i am seeing in your screen shot you are assign 

GetUser(GetUserId()).User.Name

Not using this value-


Find this screen shot- red line is wrong which is giving error and Bule line right for using this.




Thanks

Rahul Sahu

Rahul Sahu wrote:

Hi David,

As i am seeing in your screen shot you are assign 

GetUser(GetUserId()).User.Name

Not using this value-


Find this screen shot- red line is wrong which is giving error and Bule line right for using this.




Thanks

Rahul Sahu

My idea is storing the current username in the variable GuardaObraFuncionario but its not working any suggestion ?

Hi David,

Wouldn't you need to save the updated record to the database?... otherwise it will be discarded as soon as you leave the current action.

Check the UpdateGuardaObras entity action that you can find by expanding the entity GuardaObras (on the Data tab)

Hope this helps

I've tried  this 

But getting this error 

David Fernandes wrote:

I've tried  this 

But getting this error 


Hi David,

Which record you want to update its not find Primary Key for update.

Please check using debugger have the ID passed for UpdateGuardaObras  or not.

Rahul Sahu wrote:

David Fernandes wrote:

I've tried  this 

But getting this error 


Hi David,

Which record you want to update its not find Primary Key for update.

Please check using debugger have the ID passed for UpdateGuardaObras  or not.

I want to save the user that is logged into a variable in GuardaObras table ...

Iam using assign to store user into the GuardaObras table then updating it but its not working 


Your GetGuardaObras aggregate is not returning any records... so you are trying to update a record that does not exist (has no Id) and it raises that exception.

What are you expecting to read in your GetGuardaObras aggregate? and on your GetUsers aggregate, by the way...

Solution

From my understanding you have multiple things wrong in that action.

You have to get the Id of GuardaObra as an input and use it on the aggregate to guaranty that you are updating the correct record.



Then you should check if it exists, to update it, if it does not exists you should do nothing.

 

The User aggregate was doing nothing, you are using the GetUser function to get the user username.

Hope it helps.

Solution