How to get all child incidents number associated with particular Parent incident using Script ?

Tejas16
Tera Contributor

How to get all child incidents number associated with particular Parent incident using server side Script? 

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

Run below script in background script, it will print all child incidents.

var inc = new GlideRecord('incident');
inc.addQuery('parent', ' ');  // pass the sys_id of parent incident
inc.query();
while(inc.next())
{
gs.print(inc.number);  // it will print all child incident numbers
}


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

View solution in original post

3 REPLIES 3

RaghavSh
Kilo Patron

Run below script in background script, it will print all child incidents.

var inc = new GlideRecord('incident');
inc.addQuery('parent', ' ');  // pass the sys_id of parent incident
inc.query();
while(inc.next())
{
gs.print(inc.number);  // it will print all child incident numbers
}


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

Tejas16
Tera Contributor

Only Small change is there:

Replace parent with parent_incident.

How write a background script in servicenow to get the parent and child incident records for the entire incident table in database and not just for one parent incident record