- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 07:49 AM
I have multiple fields on a form. I'm trying to get the value of a choice-list field called 'patient_category'. But, the following code always returns the value of another field on the form -- the patient_name field. regardless of what field I specify as the getDisplayValue parameter, the system always returns the value of the patient_name field. I'm totally new to scripting in ServiceNow so am wondering what I am missing.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert(g_form.getDisplayValue('patient_category'));
}
Thanks in advance for your help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2017 09:14 PM
Hi Mike,
Can you try this code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert(g_form.getDisplayBox('patient_category').value);
}
P.S: Hit Like or Correct depending on the impact of response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 01:31 PM
Please share the screen shot of the on change script and the form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 08:12 AM
Hi Mike,
Try using something as below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var chk1=g_form.getValue('patient_category');
alert('Patient category is ',chk1.getDisplayValue());
//alert(g_form.getDisplayValue('patient_category'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 01:15 PM
Thanks for the reply. This suggestion generated the following error. onChange script error: TypeError: chk1.getDisplayValue is not a function function () { [native code] }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 06:39 PM
getDisplayValue() is NOT supported in client side scripting. you can use the getReference() function to get the value, please check if this helps,
function onChange(control, oldValue, newValue, isLoading) {
var pcat = g_form.getReference('patient_category', doAlert);
}
function doAlert(pcat) {
alert(pcat.name);
}
or else you need to do GlideAjax call to fetch the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 08:35 AM
use this code
var choiceValue = g_form.getValue(<fieldName>);
var choiceLabel = g_form.getOption(<fieldName>, choiceValue).text;
Regards,
Sachin