The CreatorCon Call for Content is officially open! Get started here.

How to get current logged in user userid in client script?

Akki1
Tera Contributor

How to get current logged in user userid in client script? I don't want sys_id i want userid

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Akki1 

you can use g_user object and this line to get userid/user name

g_user.userName
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Akki1 

you can use g_user object and this line to get userid/user name

g_user.userName
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

how to get Phone number in this case?

Hi @Ram050670 

Please try out below code, it should work on client side (UI Policy or Client Script):

var gr = new GlideRecord('sys_user');
gr.get(g_user.userID);
var phone = gr.phone;

 

Please mark this answer helpful, if it worked for you.

 

Thanks

Fazal

Vishnu k
Tera Contributor

Hi @Akki1 
You can use the g_user object to fetch logged in user details like firstname/ fullname etc.
g_user.userID