How to get logged in user (Id/user name) in UI Script?

vinuret
Kilo Contributor

Hi,

I have a requirement to run an external script (to configure appdynamics with Service portal) when the Service portal page is loaded. I have created a UI Script and added the external script content in that. I have added this script to the Portal theme. I can see that the script is running fine when the portal is loaded.

Now my query is how to get the logged in user info in the UI Script. I tried the below options.

var userName = gs.getUserName() // giving error that gs is not defined

var usreName = g_user.userName // giving error that g_user is not defined.

Can anyone please help me to sort this out? I need to get the logged in user info in my UI Script.

Thank you,

Vinu

7 REPLIES 7

caliban
Tera Expert

Hi Vinu,

I think this could help you out.

replace "g_user.userName" with "${gs.getUser().name}".

See this answer in context here:

How to check current user details from a UI page

 

vinuret
Kilo Contributor

Hi Caliban,

Thank you for your quick response but ${gs.getUser().name} returns empty.

Regards,

Vinu

PriyaRanji
Tera Guru

Hi, 

Could you please try with gs.getUserID(); - which gives you the user name based on which you can glide user table to fetch the corresponding details which you are looking for!

Thanks!

Priyanka R