The CreatorCon Call for Content is officially open! Get started here.

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

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

Allen Andreas
Administrator
Administrator

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!

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


}

thains. i had read about the callback function and glossed right over it unfortunately. Really appreciate it. Moving onward YAY

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!