Shamma Negi
Kilo Sage
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12-13-2023
02:59 AM
Hi All,
It is a very useful API specially helps you to reduce writing less code in Client Side Scripting. ShortCut metjods to fetch logged in user values. Please have a look:
GlideUser API
The GlideUser API provides access to information about the current user and current user roles. Using the GlideUser API avoids the need to use the slower GlideRecord queries to get user information.
The GlideUser methods and properties are accessed through a global object (g_user) that is only available in client scripts
Common Useful Examples are as below:
Example 1:firstName (Returns the current user's first name)
alert('first name = ' + g_user.firstName);
Example 2: lastName (The current user's last name.)
alert('last name = ' + g_user.lastName);
Example 3: userID (Returns the sys_id of the current user)
var userID = g_user.userID; alert('Current user ID = ' + userID);
Example 4: userName
This property is the current user's username, for example gsmith02. It is not the user's name, for example George Smith.
var userName = g_user.userName; alert('Current user = ' + userName);
Example 5: getClientData(String key)
Returns a client value set using setClientData() or GlideSession -- putClientData().
var loginLanguage = g_user.getClientData("loginlanguage");
Example 6: FullName()
Returns the first and last name of the current user.
var formalName = g_user.getFullName();
Example 7: hasRole()
Returns true if the current user has the specified role or the admin role.
var isInternal = g_user.hasRole('snc_internal', true);
var isItil = g_user.hasRole('itil');
Example 8: hasRoleExactly()
Determines whether the current user has the specified role only. Doesnt return true for admin role
var isInternal = g_user.hasRoleExactly('snc_internal', true);
var isItil = g_user.hasRoleExactly('itil');
Example 9: hasRoleFromList()
Returns true if the current user has at least one of the specified roles or has the admin role.
var isOK = g_user.hasRoleFromList("itil, maint");
Example 10 :hasRoles()
Returns true if the current user has any role.
var yesRole = g_user.hasRoles();
Hope this helps.
I hope this article helpful. Please mark it as helpful and bookmark if you like it.
Regards,
Shamma Negi
- 258 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.