why array printing one number multiple times instead of printing every record number under query??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 02:30 AM - edited 05-07-2024 02:31 AM
var abc = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('caller_id=77ad8176731313005754660c4cf6a7de');
gr.query();
while(gr.next()){
abc.push(gr.number);
}
gs.print(abc);
can anyone give me explanation in laymen terms??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 02:32 AM
Replace
abc.push(gr.number);
with
abc.push(gr.number.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 02:37 AM
Hi Jaspal, Thank you for response
already i got to know to print exact result either by adding toString() or by using getvalue method but the expecting is why its behaving so? what is the reason behind it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 02:45 AM
toString() will store the memory location in the array, not the actual record value, so you'll get an array of all of the same record value if you don't.
Use toString() on the end of object value assignments to prevent printing same values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 02:56 AM
Hi @KM SN ,
try this code :
var abc = [];
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', '77ad8176731313005754660c4cf6a7de');
gr.query();
while (gr.next()) {
abc.push(gr.getValue('number'));
}
gs.info(abc.join(', '));
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....