Array returns "undefined".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 09:08 AM
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());
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 09:48 AM
appsArr.push(gr2.ci_item.toString()); //what is ci_item here?
These are the CI values from the task_ci query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 09:33 AM
Just try without to string
current.addQuery('sys_id','IN',applications);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 09:52 AM
The problem is in the second glide record....its returning null.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 11:00 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 11:10 AM
gs.info returns null