- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 06:53 AM
Hi Community,
I'm using a UI page on user record, the UI page has a field called user name, when the UI page is opened I want to populate the username with the current user record name. any help in script.
Thanks in advance.
Please find the attached screen shot for reference
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 04:14 AM
now it should work
we are sending userFullName from UI action; so update as this
<g:evaluate var="jvar_name" expression="RP.getWindowProperties().get('userFullName')" />
<p>full name ${jvar_name}</p>
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 07:06 AM
Hope you are using g:ui_reference name to refer the user record. To set default value you use the below line
<g:ui_reference name="item_ref_field" table="sys_user" value="${gs.getUserID()}" displayvalue="${gs.getUser().fullName}"/>
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 08:12 AM
Hi Palani Kumar,
This is populating the current logged in user name not the user record user name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 07:07 AM
Hi,
you can pass the current user record sys_id to that UI page and set that
Can you share the UI action and UI page scripts?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 07:50 AM
Hi Ankur,
The Ui page script
<?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:ui_form>
<html>
<body>
<input type="hidden" name="hold_or_submit" id="hold_or_submit" value="" />
<input type="hidden" name="start_error" id="start_error" value="false" />
<input type="hidden" name="end_error" id="end_error" value="false" />
<!--<j:set var="jvar_name" value="${RP.getWindowProperties().get('user_name')}" />-->
<style>
select {
width: 270px;
margin: 5px;
height: 30px;
}
</style>
<table style="border-spacing:0 5px">
<tr>
<g:evaluate var="jvar_request" jelly="true">
var UserName = jelly.jvar_name;
var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id' current_sys_id);
gr.query();
gr.next();
gr;
</g:evaluate>
<td>User name:</td>
<j:if test="${gr.sys_id !=''}">
<td><g:ui_reference name="user_name" id="username" expression="RP.getWindowProperties().get('user_name')" /></td>
</j:if>
</tr>
<tr>
<td>Stockroom:</td>
<td> <g:ui_reference name="stockroom" id="stockroom" table="alm_stockroom" completer="AJAXTableCompleter" onchange="fetchModels()"/></td>
</tr>
<tr>
<td>Model:</td>
<td>
<g:ui_reference name="model" id="model" table="alm_consumable"/></td>
</tr>
<tr>
<td>Model category:</td>
<td> <g:ui_reference name="model_category" id="modelCategory" table="cmdb_model_category" query="sys_created_by!=system^name=consumable"/></td>
</tr>
<tr>
<g:evaluate jelly="true" object="true">
var rec = new GlideRecord('sys_choice');
rec.addQuery('table', 'alm_consumable');
rec.addQuery('element', 'u_catalog_category');
rec.query();
rec;
</g:evaluate>
<td>Catalog category: </td>
<td> <select name="catalog_category" id="catalogCategory">
<option value="">-- Select --</option>
<j:while test="${rec.next()}">
<option value="${rec.value}">${rec.label}</option>
</j:while>
</select></td>
</tr>
<tr>
<td>Installed date:</td>
<td> <g:ui_date_time name="installDate" id="installDate" table='alm_comsumable' field='install_date'/></td>
</tr>
<tr>
<td>Quantity:</td>
<td> <input type="text" id="quantity" name="Consumablequantity"
table="alm_consumable" /></td>
<!--<g:ui_date_time name="Quantity" id="Quantity" table='alm_comsumable' displayValue="$[quantity]"/>-->
</tr> </table>
<br/>
<tr>
<td><g:dialog_button id="cancel" title="${gs.getMessage('Cancel')}" type="${jvar_cancel_type}"
style_class="btn btn-default" onclick="return cancelConvert();" style="min-width: 5em;" >${gs.getMessage('Cancel')}</g:dialog_button>
<g:dialog_button id="submit_for_review" title="${gs.getMessage('submitting')}"
type="${jvar_cancel_type}" style_class="btn btn-primary" onclick="return cancelSubmit();"
style="min-width: 5em;"> ${gs.getMessage('Submit')}</g:dialog_button></td>
</tr>
</body>
</html>
</g:ui_form>
</j:jelly>
UI action:
function addConsumable(){
var dialog = new GlideDialogWindow("user_consumable_dialog");
dialog.setTitle(getMessage("Add Consumables"));
dialog.setPreference("username",g_form.getValue('user_name'));
dialog.setPreference("stockroom",g_form.getValue('stockroom'));
dialog.setPreference("model",g_form.getValue('model'));
dialog.setPreference("model_category",g_form.getValue('model_category'));
dialog.setPreference("catalog_category",g_form.getValue('catalog_category'));
dialog.setPreference("installDate",g_form.getValue('installDate'));
dialog.setPreference("Consumablequantity",g_form.getValue('Consumablequantity'));
dialog.setWidth("500");
dialog.render();
}