- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 03:27 AM
Hi Community,
I'm trying to fetch the Name value on User record to a field in UI page calling on same record(please find the attached screenshot) can I get some help in prepopulating the Name into the User name(see screenshot) using any script in UI page.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 03:40 AM
Hi,
You will have to pass sys_id not name as your field on UI page is reference field.
In UI action, you will have pass it by below method.
var dialog = new GlideDialogWindow("test_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
dialog.setSize(1250,500);
dialog.setTitle("Page Title"); //Set the dialog title
dialog.setPreference("user_sys_id", g_form.getUniqueValue());
use in the dialog
dialog.render();
Access and set reference filed in UI page as below,
<g:ui_reference name="user" id="user" table="sys_user" value="${RP.getParameterValue('user_sys_id')}" completer="AJAXTableCompleter"/>
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 03:40 AM
Hi,
You will have to pass sys_id not name as your field on UI page is reference field.
In UI action, you will have pass it by below method.
var dialog = new GlideDialogWindow("test_dialog"); //Render the dialog containing the UI Page 'task_comments_dialog'
dialog.setSize(1250,500);
dialog.setTitle("Page Title"); //Set the dialog title
dialog.setPreference("user_sys_id", g_form.getUniqueValue());
use in the dialog
dialog.render();
Access and set reference filed in UI page as below,
<g:ui_reference name="user" id="user" table="sys_user" value="${RP.getParameterValue('user_sys_id')}" completer="AJAXTableCompleter"/>
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 04:04 AM
Hi Abhijit,
It still shows empty reference field the value is not populated
Thanks,
Shiva.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 04:33 AM
Can you please share your script so that we can help you further.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2022 04:53 AM
HTML:
<?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 onload="setDefaultValue();">
<!-- <g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysId')" />
<input type="hidden" name="userSysId" id="userSysId" value="${jvar_sysId}"/>
<g:evaluate var="jvar_name" expression="RP.getWindowProperties().get('username')" />
<input type="hidden" name="userFullName" id="userFullName" value="${jvar_name}"/>-->
<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" />
<style>
select {
width: 270px;
margin: 5px;
height: 30px;
}
</style>
<table style="border-spacing:0 5px">
<tr>
<!--<g:evaluate jelly="true" object="true">
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:while test="${jvar_gr.next()}">-->
<td><g:ui_reference name="user" id="user" table="sys_user" value="${RP.getParameterValue('user_sys_id')}" completer="AJAXTableCompleter"/>
</td>
<!--</j:while>-->
</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("user_sys_id", g_form.getUniqueValue());
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();
}