Reference field not displaying the value it stored

veena_kvkk88
Mega Guru

Hello everyone!!

I have a 'Load Incident' reference field on 'Incident' table that references 'Load Incidents' (custom) table, which has other information in addition to a reference to 'Incident' table. I want the 'Load Incident' reference field to be populated with the Load incident record that points to current incident. I used this code in Fix Script to update all incident records.

var gr = new gliderecord('incident');

gr.query();

while(gr.next()){

  var grr = new GlideRecord('u_load_incidents');

  grr.addQuery('u_incident', gr.getUniqueValue());

  grr.query();

  while(grr.next()){

  gr.u_load_incident = grr.u_incident;

  gr.update();

  }

}

It worked fine and the reference field is populated with the right value. But the value is not being displayed, both in List View and in Form view, although the value is stored. I can see the info icon that shows the correct record, and even when I display the value using form javascript alert, it displays correct value. But it is not being shown. What am I doing wrong?

Screen Shot 2016-08-02 at 2.53.17 PM.png

When I click the info icon next to Load Incident, here's where it's taking me.

Screen Shot 2016-08-02 at 2.59.48 PM.png

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Veena,



  There are few syntax errors. Your script should be this



var gr = new GlideRecord('incident');


gr.query();


while(gr.next()){


  var grr = new GlideRecord('u_load_incidents');


  grr.addQuery('u_incident', gr.getValue("sys_id"));


  grr.query();


  while(grr.next()){


  gr.u_load_incident = grr.getValue("sys_id");


  gr.update();


  }


}


View solution in original post

8 REPLIES 8

It will give you sys_id, problem with your code is you are setting u_load_incident with incident. You need to set u_load_incident with the sys_id of load incident not incident


gr.u_load_incident = grr.getValue("sys_id");




Please mark my response as correct.


Oh! I get why my assignment is wrong. But how come it was taking me to the right record when I click it?


My guess is the record is linked correctly but you are setting the value incorrectly. So it is not displaying any value on the form but at the back-end the record is still linked


Hi Abhinay,

 

I have a similar issue. There is a reference field which refers to table cmdb_ci_db_instance.

If I select any value, it does not show them all the time. Sometimes, it remains blank even if the data is there in the background.

Do you know what could be wrong? I have written no code, simply a reference field declared.

 

Thanks,

Manas