- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 03:38 AM
Hey,
Could anyone please advise on how to get the display value for any reference field (CI field) using the onSubmit Catalog Client script?
Using g_form.getValue('u_device_ref_1'), I am getting the sys_id of this field
And with g_form.getDisplayValue('u_device_ref_1'), I am getting blank value.
Thanks in Advance,
Rathika.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 03:56 AM
HI Rathika,
You can use g_form.getDisplayBox('field_name');
Thanks
Prashant
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2025 11:57 PM - edited ‎06-30-2025 12:09 AM
This worked for me hope helps you too.
var assignee = g_form.getValue('assigned_to');
var assigneeName = getDisplayValue_2('assigned_to', 'sys_display.sc_req_item.assigned_to');
// htmlID: exact HTML id from your browser's inspect window
function getDisplayValue_2(fieldName, htmlID) {
// frontend eg. CatItem by OOB
if (!window)
return g_form.getDisplayValue(fieldName);
// backend eg. RITM by OOB
if (g_form.getDisplayBox(fieldName) && g_form.getDisplayBox(fieldName).value)
return g_form.getDisplayBox(fieldName).value;
// backend eg. RITM by HTML
var el = document.getElementById(htmlID) || // try this.document... on errors
document.querySelector('[id$="' + htmlID + '"]');
if (!el) return '';
var tag = el.tagName.toLowerCase();
if (tag === 'input' || tag === 'textarea') { // reference, textbox, ...
return el.value || '';
}
if (tag === 'select') { // selectbox
var opt = el.selectedOptions && el.selectedOptions[0];
return opt ? opt.textContent.trim() : '';
}
return el.textContent.trim() || '';
}