client script g_form.getValue issue on referenced field hr_assignment_group

Christine A1
Mega Expert

 

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','');
}

}

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

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','');
}


}

View solution in original post

11 REPLIES 11

thanks. i just saw this and have moved on but i will test it. previous worked fine but I am also building an custom app so the table has literally next to no records in it so it went unnoticed but wont want it to come back and bite me. Happy Friday!

Pratiksha
Mega Sage
Mega Sage

hi, i am trying to get value from the reference field and put it to a string field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var b = g_form.getReference('core_company',callBack);
var b = g_form.getReference('core_company', callBack);

function callBack(b)
{
var a = b.state;

alert(a);
g_form.setValue('u_loc',a);
}
}

it is not working