We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

why array printing one number multiple times instead of printing every record number under query??

KM SN
Tera Expert

var abc = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('caller_id=77ad8176731313005754660c4cf6a7de');
gr.query();


while(gr.next()){


abc.push(gr.number);
}
gs.print(abc);

ManiHouse1_0-1715074227931.png

can anyone give me explanation in laymen terms??

 

 

5 REPLIES 5

Not applicable

Hi @KM SN ,

I tried your problem in my PDI and it works for me please check below 

var abc = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('caller_id=77ad8176731313005754660c4cf6a7de');
gr.query();
while(gr.next()){
abc.push(gr.number.toString());
}
gs.print(abc);

Result

SarthakKashyap_0-1715075908359.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak