Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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
Mega 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
LinkedIn

View solution in original post

3 REPLIES 3

RaghavSh
Mega 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
LinkedIn

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