- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:19 AM
Hi,
In a UI page, I need to check whether any user is currently logged in or not. I tried the below things to retrieve the details for checking,
1) I tried using g_form.userName in the client section of the UI Page. But i didn't get the user name.
2) I also tried in the Processing Script section by using the gs.getUserID() and tried to log the result. However here too i'm unable to see user name.
Can anyone please suggest, how should i try to retrieve current user details from a UI page?
Regards,
Kamal
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 01:31 PM
For future reference if you need to actually get the username of the logged in user, one way to do it is use ${gs.getUser().name} or other properties like:
${gs.getUser().name} // same as username
${gs.getUser().firstName}
${gs.getUser().lastName}
${gs.getUser().fullName}
${gs.getUserID()}
Putting this in your example you gave earlier you would replace "g_user.userName" with "${gs.getUser().name}". Make sure you include the quotes.:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<head>
<script>
function myFunction()
{
alert('Hi');
var usr = "${gs.getUser().name}"; //remember quotes are still needed
alert('Bye ' + usr);
document.getElementById('user').innerHTML = usr;
}
</script>
</head>
<body onload="myFunction()">
<div id='user'></div>
</body>
</html>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:25 AM
Property Summary | |
Property | Description |
userName | User name of the current user. |
userID | Sys_id of the current user. |
firstName | First name of the current user. |
lastName | Last name of the current user. |
Click below link for more info.
GlideUser (g user) - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:28 AM
1) g_user.userName;
2) g_user.userID;
3) g_user.firstName;
4) g_user.lastName
g_user is client side object we can user details in client side using g_user. client side script are like ui polcies, clientscript
gs is server side object we can details in server side scripts like Business rule , includescript
Regards,
Harish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:40 AM
Hello Harish,
Thanks for your response. But the issue which i'm facing is that, In the "Client Script section of the UI page" i already tried using g_user.userName but its not returning any value.
When i tried using g_user.userName in a separate client script, it works fine.
I'm not sure why it is not working in UI page client script section.
Regards,
Kamal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:46 AM
Please send your ui page code.