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:26 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-28-2022 11:34 PM
Hi Priya,
Could you please elaborate on your requirement?
The solution provided by
As per my understanding, you have 1 CMDB CI record -- A, but it is associated with more than one IP Address records (P, Q, R,...)
You want to push the IP addresses of all the matching records in an array. What exactly do you mean by:
but i want to push IP address once in array,
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:35 PM
yes, For 1 ci record there are more than one Ip address associated with it, and if i use it in while loop , It stores one value each time. If i push these value outside it puch only one value.
I want these 3 values of ip address to be pused once in the array , and i have more than one CI record.
Script: sys_id8e01285f1bc4d990635f9714b24bcbac10.244.71.68
*** Script: sys_id8e01285f1bc4d990635f9714b24bcbac10.244.71.68,192.168.35.101
*** Script: sys_id8e01285f1bc4d990635f9714b24bcbac 10.244.71.68,192.168.35.101,10.244.71.4
// i want this result so that i could populate it in other table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:43 PM
Just make sure to use
array.push(IP.getValue('ip_address')); as directly using GlideRecord reference causes problem in arrays as it stores references of last record only hence only the last value comes 3 times
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 12:05 AM
Got your requirement!
Let's say there 3 netmask CMDB CI - A, B, C, and these 3 CIs have IP addresses (P, Q, R, X, Y, M, N) as provided below:
- A - P, Q, R
- B - X, Y
- C - M, N
The final result required is:
sys_id<A>: [P, Q, R]
sys_id<B>: [X, Y]
sys_id<C>: [M,N]
Can we go for JSON object rather than just Array?
Please confirm.
Thanks and regards,
Kartik