How to check the current logged in user in servicenow using on load client script.

siddharth26
Tera Guru

How to check the current logged in user in servicenow using on load client script.

1 ACCEPTED SOLUTION

Have a look at the link I provided. It's literally mentioned there.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

5 REPLIES 5

Chavan AP
Tera Guru

hey sid,

 

Please refer below:

The GlideUser (g_user) Class

The GlideUser API provides methods and non-method properties for finding information about the currently logged in user and their roles. The typical use cases are personalizing feedback to the user and inspecting user roles. Note that client-side validation in any web application is easily bypassed.

The GlideUser API has properties and methods to:

  • Retrieve the user's:
    • First name
    • Full name
    • Last name
    • User ID
    • User name
  • Determine if a user has a particular role assigned

The GlideUser methods and non-method properties are accessed through the global g_user object which is only available in client-side scripts. To use methods and properties from the GlideUser class use the syntax:

g_user.<method or property name>

For example, the GlideUser API has a property called userName. The userName property's value is the currently logged in user's user name. The example script shows the difference between the firstNamelastNameuserName, and userID property values.

alert("g_user.firstName = " + g_user.firstName 
   	+ ", \n g_user.lastName = " + g_user.lastName 
   	+ ", \n g_user.userName = " + g_user.userName 
   	+ ", \n g_user.userID = " + g_user.userID);

The alert generated by the script is:

The output from the sample script.
 
 
 
if this resolves your query please mark correct and helful
 
regards
ajay
Chavan AP
[ Architect | Certified Professional]

Was this response helpful? If so, please mark it as Helpful and Accept as Solution to help others find answers.