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 print all the child incidents numbers.

hemasree kanduk
Tera Contributor

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

3 ACCEPTED SOLUTIONS

OlaN
Tera Sage
Tera Sage

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'));
}

View solution in original post

RaghavSh
Mega Patron

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
LinkedIn

View solution in original post

Sagar Pagar
Tera Patron

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

The world works with ServiceNow

View solution in original post

3 REPLIES 3

OlaN
Tera Sage
Tera Sage

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'));
}

RaghavSh
Mega Patron

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
LinkedIn

Sagar Pagar
Tera Patron

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

The world works with ServiceNow