g_form.getDisplayValue('u_student') is not working in client script in “Xanadu” version

abhisekransingh
Tera Contributor

i have a onload client script and i am retriving displayvalue  of a refernce field('u_student).But it is not working.

 

function onLoad() {
//Type appropriate comment here, and begin script below

var stu_value=g_form.getDisplayValue('u_student');
alert(stu_value);
 
 
}
7 REPLIES 7

vennelasai
Tera Contributor

Hi @abhisekransingh 

 

Please use below code,

I am taking reference id caller field on incident form. Please replace as per your requirement.

var student = g_form.getReference('caller_id'); //works only your field type is reference

alert(student.user_name);

 

Please mark it as correct If this helps you.

Thanks,

Vennela

Chaitanya ILCR
Kilo Patron

Hi @abhisekransingh 
use the GlideAjax or GlideReocrd or g_form.getDisplayBox('u_student').value(this might not work in portals)

Regards,
Chaitanya

SN_Learn
Kilo Patron
Kilo Patron

Hi @abhisekransingh ,

 

getDisplayValue() won't work in client scripts. Also, you will find some API that are not showing because maybe ServiceNow has not documented it but it will work and fulfill your requirement.

 

In ServiceNow Docs you can find the API:

SN_Learn_0-1731480506229.png

 

Try the below:

var stu_value=g_form.getDisplayBox('u_student').value;
alert(stu_value);

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.