- 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-16-2022 04:14 AM
Please share complete script and client script configuration screenshot
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 08:27 AM
Hi Ankur,
PFB script. I need the display value when the value of rsa = 'Yes'
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var rsa = newValue;
if (rsa == 'no') {
top.window.open(url, '_blank');
} else {
if (window == null) {
var valuePortal = g_form.getDisplayValue('who_s_this_request_for');
alert('Portal->' + valuePortal);
} else {
var valueNative = g_form.getDisplayBox('who_s_this_request_for').value;
alert('Native->' + valueNative);
}
}
}
Thanks,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 08:31 PM
Hi,
Did you ensure Isolate Script is set to False for this client script
the blog I created has worked for many members.
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-17-2022 08:45 AM
Hi Ankur,
It seems your solution was working after all.
The reason it was not working at first might be because I was utilizing a multi row variable set and with your script I was trying to get the display value of a reference field which was not part of the multi row variable set.
The script seems to be working when I am trying to get the display value of a reference field which is part of the multi row variable set.
So I guess, since I am using g_form, it only takes in the value from the current form which is different in case of multi row variable set.
But one thing I noticed was that the Isolate Script functionality does not have any impact. The script seems to be working even if the value of Isolate Script is set to true.
Also, on another note, I have another solution for this scenario that is to use getReference(). Which solution do you recommend ?
Thanks,
Gopi