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.

Array returns "undefined".

Victor Ruiz
Tera Guru

Attempting to retrieve a list of CI's but the second Glide query returns undefined, what am I missing?

 

var appsArr = [];

var gr2 = new GlideRecord('task_ci');
gr2.addQuery('task', current.sys_id);
gr2.query();
while(gr2.next()){

appsArr.push(gr2.ci_item.toString());

}

var applications = [];

for(var i=0; i<appsArr.length; i++){

var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child',appsArr[i]);
gr.query();
gs.log(gr.parent); //RETURNS UNDEFINED
while(gr.next()) {

applications.push(gr.parent.toString());
}
}
current.addQuery('sys_id','IN',applications.toString());

 

 

20 REPLIES 20

appsArr.push(gr2.ci_item.toString()); //what is ci_item here?

 

These are the CI values from the task_ci query.

 

 

VigneshMC
Mega Sage

Just try without to string

 current.addQuery('sys_id','IN',applications);

The problem is in the second glide record....its returning null.

 

SanjivMeher
Mega Patron
Mega Patron

 

Can you try

var appsArr = [];

var gr2 = new GlideRecord('task_ci');
gr2.addQuery('task', current.sys_id);
gr2.query();
while(gr2.next()){

appsArr.push(gr2.getValue("ci_item")+"");

}

var applications = [];

for(var i=0; i<appsArr.length; i++){

var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child',appsArr[i]+"");
gr.query();

while(gr.next()) {
applications.push(gr.getValue("parent")+"");
}
}
gs.info('final list of apps'+applications.toString());
current.addQuery('sys_id','IN',applications.toString());

Please mark this response as correct or helpful if it assisted you with your question.

gs.info returns null