- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:02 PM
I am using a onChange client script to clear out values or change values in other fields on the form.
I am struggling with how to get the display value of a referenced field if possible. the her_assignment_group is a reference to the Group table.
The trouble is with the hr_assignment_group. If i use the getValue, i get the sys_id. If i use the getReference, i get Undefined. How do i get the display value? Else, what are my options to use as a condition?
------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
alert("Hi "+g_form.getValue('hr_assignment_group'));
if (newValue == 'KM HR') {
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
g_form.setValue('hr_ticket_type','kmhr_mgmt');}
else if (newValue == 'Time') {
g_form.setValue('hr_ticket_type','time_mgmt');
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:34 PM
You can get the name by using getReference with callBack function
Try the below script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var group = g_form.getReference('hr_assignment_group', callBack);
}
function callBack(group){
var name = group.name;
if (name == 'KM HR') {
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
g_form.setValue('hr_ticket_type','kmhr_mgmt');
}
else if (name == 'Time') {
g_form.setValue('hr_ticket_type','time_mgmt');
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:31 PM
You would normally use .getDisplayValue();
But I don't think that works in Client Script.
So you'd need to do:
var group = g_form.getReference('hr_assignment_group');
alert("Hi " + group.name);
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:34 PM
You can get the name by using getReference with callBack function
Try the below script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var group = g_form.getReference('hr_assignment_group', callBack);
}
function callBack(group){
var name = group.name;
if (name == 'KM HR') {
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
g_form.setValue('hr_ticket_type','kmhr_mgmt');
}
else if (name == 'Time') {
g_form.setValue('hr_ticket_type','time_mgmt');
g_form.setValue('hr_assigned_to','');
g_form.setValue('kmhr_business_service','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:41 PM
thains. i had read about the callback function and glossed right over it unfortunately. Really appreciate it. Moving onward YAY

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:56 PM
Just wanted to say that I said the same thing that dvp did...and my method works as well without a callback...
You'd just do:
if (group.name == 'Name of Group') {
do blah blah
}
Thanks 😉
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!