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

Chuck Tomasi
Tera Patron

Hi Veena,



What is the display field set on the u_load_incidents table?



From the Load Incidents form, right click the header and say Configure> Dictionary and see which field has the value true in the Display column.



Also, double check your ACLs to ensure you have read access on the entire table as well as all the fields on u_load_incidents.



System Dictionary - ServiceNow Wiki


Using Access Control Rules - ServiceNow Wiki


Security Best Practices - ServiceNow Wiki


Contextual Security - ServiceNow Wiki    


Hi Chuck,



The display value is set correctly to incident reference field. And the ACL's aren't blocking me either.


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();


  }


}


Hey Abhinay! That worked perfectly! Thank you!



But I don't understand why mine was wrong. getUniqueValue() will return the sys_id of the record, wouldn't it?