Getting reference field value in client script

venkatkk
Tera Contributor

I have a record producer where Department , CostCenter is added. CostCenter is dependent on Department. All these values lies in cmn_department table.

i added a Catalog Client script to pickup the values But it shows sys_id instead of values since CostCenter is Reference field. Pls help how can i get the value of Cost Center ?

Catalog Client Script

OnChange

Department

function onChange(control, oldValue, newValue, isLoading) {

  if (isLoading || newValue == '') {

  return;

  }

  var dept_new = g_form.getValue(newValue);

  var gr = new GlideRecord('cmn_department');

  gr.addQuery('name', newValue);

  gr.query();

  if(gr.next())

  {

  //var cc_value = getRefernce(gr.cost_center);

  var cc_value = gr.getDisplayBox("cost_center").value;

  g_form.setValue('cost_centre_new', cc_value);

  g_form.setValue('gl_code_new', gr.u_gl_code);

  }

  //Type appropriate comment here, and begin script below

}

when i use   g_form.setValue('cost_center_new', gr.cost_centre); it gives me Sys_id

Pls Help

1 ACCEPTED SOLUTION

Pls try below script include code is working:-




var getDepartment = Class.create();


getDepartment.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  deptName:function() {
var val='';
  var deptId = this.getParameter('sysparm_dept');
      var gr = new GlideRecord('cmn_department');
 
  gr.addQuery('sys_id',deptId);
  gr.query();
  if (gr.next())
{
val=gr.getDisplayValue('cost_center');
}
return val;
}
});



-------


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


View solution in original post

13 REPLIES 13

Rushikesh Mandh
Mega Expert

Hi Venkat,



Please try following:



g_form.getDisplayBox('fieldname').value


tanumoy
Tera Guru

Go to that particular table (cmn_department) from System Definitions --> Tables and make the Display Value "True" for Name column.


current.tasker_history=current.getDisplayBox('tasker_status').value



Returns undefined and yes this field in table description is set to display.


Finally figured this out:


I have a form named "tasker" that looks up a status from a table called "status" for a variable on this table called "status".



I want to write the tasker status as it changes to a tasker history field. But because the status is a reference field all I get is the record's sys_id. So to lookup its value, you have to call the original record.



var id=current.tasker_status;
var status=new GlideRecord('x_64719_letters_status'); //x_64719 is my instance name


status.addQuery('sys_id',id);


status.query();
status.next();


current.tasker_history=current.tasker_history +" " +status.status+ gs.getUser().getDisplayName()+"<BR>";


current.update();