gs.getUserName() returns old data

Community Alums
Not applicable

Hello,

I am currently displaying the logged in user's first name in the portal using "gs.getUser().getFirstName();".

My first name 'shruthi' is displayed. When I am logged in, I go to my user record and change my first name as "Shruthij". After refreshing the portal homepage, gs.getUser().getFirstName() still shows "Shruthi". When I log out and log in again, it shows "Shruthij".

find_real_file.png

Why is this session dependent?

 

Thanks

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

getUser() returns a GlideMemoryRecord, which is loaded when you first log in.

find_real_file.png

If you want the real-time details, you'd need to either flush the cache (as mentioned above) or do a GlideRecord lookup

var grUser = new GlideRecord('sys_user');
grUser.get(gs.getUserID());

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

10 REPLIES 10

Jagadeesh R1
Tera Expert

Hello Shruthi,

       I am not sure whether this Link could help. I faced the similar requirement where in the portal there is a list widget of a custom table (say incidents) and when any user inserts the record (incident) in the traditional UI, the portal list is not updated. So I came across the Link. The implementation might have to be done on Login widget

 

Regards,

Jagadeesh

Community Alums
Not applicable

That's a good idea using a record watcher but I am assuming no ones change their name so recurrent that require the need to place a record watcher...

Vishal Khandve
Kilo Sage

Hi,

can you please check first on sys_user table.?

 

Thanks!

Shweta KHAJAPUR
Tera Guru

That is due to the session created when form loaded. If you make changes to the user then it'll not apply to the current session. You have to log out and again log in to see changes.

Rahul Kumar17
Tera Guru

hi

clear Cache.

https://instance_number.service-now.com/cache.do

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar