- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 11:42 PM
Hi,
We are using a reference field - 'requester' in the catalog form which reference to sys_user table.
We need to get the display value of this field in catalog client script for building some functionality.
I tried various methods suggested in community - like g_form.getDisplayValue(), g_form.getDisplayBox(), etc but nothing seems to be working fine.
Please let me know if there is a way to do this.
Thanks,
Gopi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 11:47 PM
Hi,
I have written blog for this and it works in native + portal
Get Display value of reference variable Service Catalog
If my blog helps please mark it helpful and also bookmark it
sharing the script here as well
Note: The solution requires this Isolate Script field as false considering the window object in script being used
Example: my variable "requester" is reference to sys_user table
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(window == null){
var valuePortal = g_form.getDisplayValue('requester');
alert('Portal->' + valuePortal);
}
else{
var valueNative = g_form.getDisplayBox('requester').value;
alert('Native->' + valueNative);
}
//Type appropriate comment here, and begin script below
}
Output:
Native:
Portal:
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
03-15-2022 11:47 PM
Hi,
I have written blog for this and it works in native + portal
Get Display value of reference variable Service Catalog
If my blog helps please mark it helpful and also bookmark it
sharing the script here as well
Note: The solution requires this Isolate Script field as false considering the window object in script being used
Example: my variable "requester" is reference to sys_user table
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(window == null){
var valuePortal = g_form.getDisplayValue('requester');
alert('Portal->' + valuePortal);
}
else{
var valueNative = g_form.getDisplayBox('requester').value;
alert('Native->' + valueNative);
}
//Type appropriate comment here, and begin script below
}
Output:
Native:
Portal:
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
03-16-2022 12:21 AM
Hi Ankur,
Thank you for your update.
I had already tried the method you mentioned in your blog. Awesome blog btw !!
It seems to be working fine if the the OnChange catalog client script is running on change of the variable value of the concerned reference field.
But my scenario is, I have a Yes/No field, selecting the value as 'Yes' should get me the display value of the Requested User (reference field to sys_user table). So the OnChange script runs on change of the Yes/No variable.
I believe I need to use either getReference method or a GlideAjax for this scenario. Please suggest your thoughts.
Thanks,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 12:40 AM
Hi,
let the script run on change of any variable the syntax and logic remains the same
so it should work fine
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
03-16-2022 04:04 AM
Hi Ankur,
For some reason, it is showing empty.
g_form.getDisplayValue() is returning null.
Thanks,
Gopi