Unable to get value of referance field in client script

Snehal13
Kilo Sage

I am trying to get value of ref field in client with g_form.getValue("fieldname"); but it returns nothing.

Even g_form.getDisplayBox("fieldname"); gives no value.

All other field values are getting returned in the client script except ref field.

What is alternative.

12 REPLIES 12

SANDEEP28
Mega Sage

@Snehal13 getDisplayBox() method syntax is depends on where you are using it, whether its classic UI or Service Portal.  I tested below in PDI and it works fine. Also check your field backend name.

alert(g_form.getDisplayBox('cost_center').value);    //--classic UI

alert(g_form.getDisplayValue('cost_center'));        //--service portal

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

 

I forgot to add- This is a workspace client script. 

var value = g_form.getDisplayBox('fieldName').value; isnt working. 

var value = g_form.getValue("fieldname");  also not working to retrieve value

amaradiswamy
Kilo Sage

@Snehal13 

 

You may try using getReference or GlideAjax.

 

sample code snippet:

vfunction onChange(control, oldValue, newValue, isLoading) {
    g_form.getReference('caller_id', doAlert); // doAlert is our callback function
}
 
function doAlert(caller) { // reference is passed into callback as first arguments
   if (caller.getValue('vip') == 'true') {
      alert('Caller is a VIP!');
   }
}