- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:01 PM
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?
When I click the info icon next to Load Incident, here's where it's taking me.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:10 PM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:21 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:25 PM
Oh! I get why my assignment is wrong. But how come it was taking me to the right record when I click it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2018 04:11 AM
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