g_form.DisplayBox('') is not working in the portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 04:47 AM
Hi All,
Actually, I need to get the value of the reference field. So I am using 'g_form.DisplayBox('')' but it not working in the portal and gives a javascript console error.
Can anyone help me with that?
Note: The field refers to the Service offering table and I need to auto-populate the service offering name in another field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 05:14 AM
You can use catalog client script and client callable script include to achieve your requirement.
and use g_form. getDisplayValue(); in your client script for reference only fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 05:15 AM
Hi
Use
g_form.getDisplayValue("variable_name"); //but not recommended
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 05:18 AM
I had written blog for this 2 years ago and it works in both Native + Portal
If my blog helps then mark it helpful and also bookmark it
Get Display value of reference variable Service Catalog
Sharing the solution here as well
1) For portal -> getDisplayValue()
2) For native -> getDisplayBox()
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