How to get the display name of reference field if using g_form.getReference

Priyanka132
Giga Contributor

Hi All,

I am using g_form.getReference to populate users details in a catalog item via client script. For a few fields in user profile like Business Unit, Department, cost center, I am getting the sys_id instead of the display value.

Since these fields are reference field , the value returned is sys id. How can i get the display value instead of the sys id.

 

find_real_file.png

 

var user= g_form.getReference('requested_for');
g_form.setValue('business_unit',user.u_business_unit.u_name);    ///business unit is a reference field on user table

 

I understand i can use asynchronous glide record in the client script to populate. but not sure if that is recommended

 

 

 

 

 

1 ACCEPTED SOLUTION

ArunKRam
Giga Expert

Hi Priyanka,

I think the best way to achieve this is by using Glide Ajax. Send the sysid to the script include, query the tables and return all the display values in an array.

Thanks,

Arun

View solution in original post

12 REPLIES 12

Hi thank you for your assistance, i ended using glideajax to fullfill this requirement

Mohammed_Iqbal
Tera Guru

Hey Priyanka,

for gating actual value from reference  field in client script we have g_form.getDisplayBox(field_name).value

use this  script and let me know if any query regarding this.

var gr = g_form.getReference('requested_by', findMyDetails);
    
function  findMyDetails(gr)

{
   g_form.setValue('your_field_name', gr.mobile_phone);


   g_form.setValue('your_field_name', gr.email);


   g_form.setValue('your_field_name', gr.city);

var man=g_form.getDisplayBox('manager').value;//manager field is reference field so you need to do something like that.


  g_form.setValue('your_field_name', man);
    
   g_form.setValue('country', gr.country);
 }

 

HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.

Thanks,
Mohammed Iqbal

 

hi mohammed, i think g_form.getDisplayBox('manager').value would work if the field is in the current logged in form. However, in my case , i am intending to fetch the display value of a reference field thats present on another(user) table.

I have tried at my end its working fine.

var caller = g_form.getReference('requested_by', doAlert);

function doAlert(caller) {
g_form.setValue('manager', caller.department);
}

in above example manager field is reference field and it is referring  to cmn_department table.

 

 

 suppose if you want to fetch the department of requester and  you want to set the value of department in your   other custom field then your custom field should be same as department field which is present in user table.

your custom field is referring to the cmn_department table and it should be reference field.

 

HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.

Thanks,
Mohammed Iqbal

 

ArunKRam
Giga Expert

Hi Priyanka,

I think the best way to achieve this is by using Glide Ajax. Send the sysid to the script include, query the tables and return all the display values in an array.

Thanks,

Arun