- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 05:24 AM
Hello Experts,
I need help in below script;
arr = ['sysid,'sysid'];
I want to create a for loop and get each sysid to be passed in a gliderecord and add each value as part of encodeded query as well,
Need help in building it
Solved! Go to Solution.
- Labels:
-
Change Management
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:40 AM
Hi,
by iterating every sysId you want to fetch the child
do like this
var arr = ['sysid1','sysid2'];
var child = [];
for(var i in arr){
var gr = new GlideRecord('table');
gr.addEncodedQuery('parent!=NULL^active=true^parent=' + arr[i]);
gr.query();
while(gr.next()){
child.push(gr.sys_id.toString());
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 05:32 AM
Hi,
so what have you started with and where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 05:50 AM
I'm going to guess they're stuck at "missing ] after element list"
since their array isn't valid 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 06:41 AM
var arr = ['sysid','sysid'];
var child = [];
for(var j =0; j < arr.length ; j++){
//var eq = 'parent!=NULL^active=true^parent='+arr[j];
var gr = new GlideRecord('table');
//gr.addEncodedQuery(eq);
gr.addQuery('parent',arr[j]);
gr.query();
while(gr.next()){
child.push(gr.sys_id);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 07:23 AM
try this
var arr = ['sysid1','sysid2'];
var child = [];
var gr = new GlideRecord('table');
gr.addEncodedQuery('parent!=NULL^active=true^parentIN' + arr.toString());
gr.query();
while(gr.next()){
child.push(gr.sys_id.toString());
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader