What is the best way to get current user's email from GlideSystem?

Philippe Casidy
Tera Guru

Hi Community!

I initialize a catalogue item variable using javascript:gs.getUser().getEmail() to get current user's email.

But if the user updates the email address, I don't get the new one.

It seems I can reproduce this using a background script:

gs.print("Current user's email "+gs.getUser().getEmail());

And following this scenario

  1. run the script
    1. it will return your email address
  2. change the email address in your profile
  3. run the script again
    1. it returns the same email address as in 1.1

How can I get the new email address? Client-side friendly.
Note that I have the same behaviour with another field like 'last_name'

Thank you

Philippe

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

when you use gs.getUser().getEmail()) the values are set for the session and will change only when the user logs out and logs back in, that is when you will get the new email id at the time of user logging in.

Something like below will give you the accurate value always

var gr = new GlideRecord('sys_user')
gr.get(gs.getUserID());
gs.print("Current user's email "+gr.email);

You can add this in a function on script include and just call it from client script via glide ajax.

 

-Anurag

-Anurag

View solution in original post

8 REPLIES 8

Aman Kumar S
Kilo Patron

Hey,

So it doesn't happen even if you reload and the form is freshly loaded?

Best Regards
Aman Kumar

Hi Aman,

Yes, refreshing is not enough... you have to logout then login back to get the new value

I think this has to be done by AJAX calls via script include then.

Best Regards
Aman Kumar

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

when you use gs.getUser().getEmail()) the values are set for the session and will change only when the user logs out and logs back in, that is when you will get the new email id at the time of user logging in.

Something like below will give you the accurate value always

var gr = new GlideRecord('sys_user')
gr.get(gs.getUserID());
gs.print("Current user's email "+gr.email);

You can add this in a function on script include and just call it from client script via glide ajax.

 

-Anurag

-Anurag