- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 02:15 AM
i want to print all the child incidents numbers of a particular incident.
i tried this below code and its not working as expected.
var inc=new GlideRecord('incident');
inc.addQuery('parent_incident' , 'INC0010030');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 04:39 AM
Hi,
Parent incident expects a sysID in order to work.
So either pass a specific sysID, or add one based on some variable defined somewhere.
Also, try to use getValue and setValue methods whenever possible instead of directly dotwalking to a value.
Example below
var incGR = new GlideRecord('incident');
incGR.addQuery('parent_incident', 'some_sys_id_of_parent_incident_record_here');
incGR.query();
while (incGR.next()) {
gs.print(incGR.getValue('number'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 04:50 AM
parent_incident is a reference field and you are querying number against it, which will not work. Try below two approaches:
var inc=new GlideRecord('incident');
inc.addQuery('parent_incident.number' , 'INC0010030');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
OR
var inc=new GlideRecord('incident');
inc.addQuery('parent_incident' , 'sys_id of parent incident');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 06:20 AM
Hi @hemasree kanduk,
Try this updated scripts -
// With Parent incident number
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident.number' , 'INC0010030');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
// OR with sys_id
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident' , 'INC_sys_id');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 04:39 AM
Hi,
Parent incident expects a sysID in order to work.
So either pass a specific sysID, or add one based on some variable defined somewhere.
Also, try to use getValue and setValue methods whenever possible instead of directly dotwalking to a value.
Example below
var incGR = new GlideRecord('incident');
incGR.addQuery('parent_incident', 'some_sys_id_of_parent_incident_record_here');
incGR.query();
while (incGR.next()) {
gs.print(incGR.getValue('number'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 04:50 AM
parent_incident is a reference field and you are querying number against it, which will not work. Try below two approaches:
var inc=new GlideRecord('incident');
inc.addQuery('parent_incident.number' , 'INC0010030');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
OR
var inc=new GlideRecord('incident');
inc.addQuery('parent_incident' , 'sys_id of parent incident');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2022 06:20 AM
Hi @hemasree kanduk,
Try this updated scripts -
// With Parent incident number
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident.number' , 'INC0010030');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
// OR with sys_id
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident' , 'INC_sys_id');
inc.query();
while(inc.next()){
gs.print(inc.number);
}
Thanks,
Sagar Pagar