
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 06:26 AM
I am trying to dot walk through multiple tables in an onChange client script on the Incident table. When the Caller field on the INC form changes, I want to reference the sys_user table to see what department the Caller is in. The field that I am trying to use on the Department table is u_department_group.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getReference('caller_id');
var dept = g_form.getReference('caller_id').department;
if (newValue) {
confirm(caller.name);
confirm(dept);
}
}
caller.name prints out the user's full name as it displays in the sys_user table but when I try to print out dept, the only value I get is the sys_id. I cannot get the department name to display or any other field on the Department table to display anything.
Is this possible in a client script?
Solved! Go to Solution.
- Labels:
-
Workflow
- 6,450 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 07:51 AM
Here's the same script but using your custom field cmn_department.u_department_group:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}var caller = g_form.getReference('caller_id');
var dept = caller.department;
if (dept) {
var grDept = new GlideRecord('cmn_department');
if (grDept.get(dept)) {
confirm(caller.name + ' works at ' + grDept.u_department_group);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 07:51 AM
Here's the same script but using your custom field cmn_department.u_department_group:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}var caller = g_form.getReference('caller_id');
var dept = caller.department;
if (dept) {
var grDept = new GlideRecord('cmn_department');
if (grDept.get(dept)) {
confirm(caller.name + ' works at ' + grDept.u_department_group);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 07:26 AM
There are limitations with dot-walking on the client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 08:32 AM
I would recommend making a glide ajax call instead since the getReference isn't something that is recommend and best practice. It may be used in simple cases. But in this one, I wouldn't use it.
Let me know if you need help with the glideajax stuff.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 08:57 AM
Another option is to use .getReference() with a callback function, making it asynchronous like GlideAjax.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2016 11:13 AM
I wouldn't mind to write it as a GlideAjax but I don't have much experience writing scripts in that format.