- 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 08:08 AM
Are you sure? Whats the value you get, what did you expect to get and what is the value in patient_name field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 01:24 PM
Pretty sure. I deleted the script and re-entered it (for no apparent reason) and changed the name of the field from 'patient_category' to 'service_category'. The code now looks like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert(g_form.getValue('service_category'));
alert(g_form.getDisplayValue('service_category'));
}
The first alert returns a hex string -- probably the sys_id.
The second alert returns empty now.
The actual value in the service_category field is "Large Animal," which is what I was expecting to see. The value in the patient_name field is "Roscoe." So not sure what is happening now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 08:09 AM
Hi Mike,
Try changing the name of field and check.
Change patient_category To u_patient_category
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert(g_form.getDisplayValue('u_patient_category'));
}
If it wont work, post the complete screen shot of script and the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 01:11 PM
Thanks for the reply. Unfortunately, changing the field name didn't work.