- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 05:29 PM
Hi All,
I am new to <g:evaluate> tag, I want the Logged in user name to be displayed for which I wrote the below code but it's not working.Can anyone help me in correcting the below code.
<g:evaluate var="jvar_log_user" object="true">
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('name='+gs.getUserID());
gr.query();
gr;
</g:evaluate>
<div class="myprofile"> <img class="" src="icon.png" alt=""/>
<h4>${jvar_log_user.getDisplayValue('user_name')}</h4>
<h4>${jvar_log_user.getValue('user_name')}</h4>
Thanks,
Uma
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 05:43 PM
getUserID returns the user's sys_id rather than name as in your encoded query and you need to advance the GlideRecord using next()...Try this:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_log_user" object="true">
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_id='+gs.getUserID());
gr.query();
gr.next();
gr;
</g:evaluate>
<div class="myprofile"> <img class="" src="icon.png" alt=""/>
<h4>${jvar_log_user.getDisplayValue('user_name')}</h4>
<h4>${jvar_log_user.getValue('user_name')}</h4></div>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 05:43 PM
getUserID returns the user's sys_id rather than name as in your encoded query and you need to advance the GlideRecord using next()...Try this:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_log_user" object="true">
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_id='+gs.getUserID());
gr.query();
gr.next();
gr;
</g:evaluate>
<div class="myprofile"> <img class="" src="icon.png" alt=""/>
<h4>${jvar_log_user.getDisplayValue('user_name')}</h4>
<h4>${jvar_log_user.getValue('user_name')}</h4></div>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 07:04 PM
Further on Joe's response, you can even shorten your query to look like (note my comments in bold):
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_log_user" object="true">
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID()); // you can do this as you are only querying against sys_id
gr;
</g:evaluate>
<div class="myprofile"> <img class="" src="icon.png" alt=""/>
<h4>${jvar_log_user.getValue('user_name')}</h4></div> <!-- You don't need getDisplayValue as user_name field is a string field -->
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 01:17 AM
Hi Tom,
Do we have to put this script in processing section or HTML?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 04:47 AM
Hi Shreya,
That whole script needs to be put into the HTML section. Let me know if there is any other question.