How to check current user details from a UI page

kamal24
Kilo Explorer

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

1 ACCEPTED SOLUTION

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>


View solution in original post

20 REPLIES 20

It  works. Thanks