how do i push values in array for a record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:08 PM
Hi All,
i want to puch Ip address for the ci , which has 3 records in it. I want 3 ip to be puched to the array in one go.
this is giving me 3 records or if i print it outside, it takes only one record.
var ciSys_id;
var array=[];
var IP=new GlideRecord("cmdb_ci_ip_address");
//IP.addEncodedQuery("netmask!=64^ORnetmask=NULL^last_discoveredRELATIVEGT@dayofweek@ago@3^nic.cmdb_ci!=NULL");
IP.addQuery("nic.cmdb_ci", "8e01285f1bc4d990635f9714b24bcbac");
//IP.setLimit(5);
//IP.groupBy("nic.cmdb_ci");
IP.query();
while(IP.next())
{
ciSys_id=IP.nic.cmdb_ci;
array.push(IP.ip_address);
gs.print("sys_id"+ciSys_id+array);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:20 PM
Hi,
update as this
while pushing into array use toString()
var array = [];
var IP = new GlideRecord("cmdb_ci_ip_address");
//IP.addEncodedQuery("netmask!=64^ORnetmask=NULL^last_discoveredRELATIVEGT@dayofweek@ago@3^nic.cmdb_ci!=NULL");
IP.addQuery("nic.cmdb_ci", "8e01285f1bc4d990635f9714b24bcbac");
//IP.setLimit(5);
//IP.groupBy("nic.cmdb_ci");
IP.query();
while(IP.next()){
var ciSys_id = IP.nic.cmdb_ci;
array.push(IP.ip_address.toString());
}
gs.info("array is" + array);
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
07-28-2022 11:22 PM
I have 3 records for
nic.cmdb_ci
, but i want to push IP address once in array, So 3 ip address for one ci .how can i do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 12:09 AM
Hi,
what's the business requirement?
how would you know when to push value into array?
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
07-28-2022 11:24 PM
Hi,
Try below script and please use gs.info or gs.log to check the values
Ex: gs.log('sys id ' +ciSys_id );
var ciSys_id;
var ciarray = [];
var grci = new GlideRecord('cmdb_ci_ip_address');
grci.addQuery("nic.cmdb_ci", "8e01285f1bc4d990635f9714b24bcbac"); //filter proper records
grci.query();
while (grci.next()) {
ciSys_id = grci.nic.cmdb_ci;
ciarray.push(grci.ip_address);
}
gs.info("sys_id" + ciSys_id + ciarray[0]);
gs.info("sys_id" + ciSys_id + ciarray[1]);
gs.info("sys_id" + ciSys_id + ciarray[2]);
Hope it helps!!
Please Mark ✅ Correct if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar