- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 07:36 AM
Hi,
I am trying to execute this script in the background.
var order=new GlideRecord('sc_cat_item'); |
order.addQuery('category.title','Computer & Telephony');
order.addQuery('active',true);
order.query();
var i=0; |
var item_access=new Array();
while(order.next()){
item_access[i++]=order;
}
for(var count=0;count < item_access.length; count++){
gs.log(item_access[count].name); | ||||
} |
In the logs of the array it return the last record of the gliderecord multiple times.
Can you guide on what can be done about this?
I would like the array to store all the records of the GlideRecord and display the array iteratively.
Kind regards
Aditya
Solved! Go to Solution.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 07:44 AM
Hi Aditya,
It's mostly because the reference is not treated as a string but rather as a glide element.
You can use the order.getValue("sys_id"); to avoid getting same repeated value.
- var order=new GlideRecord('sc_cat_item');
- order.addQuery('category.title','Computer & Telephony');
- order.addActiveQuery();
- order.query();
- var item_access = [];
- while(order.next()){
- item_access.push(order.getValue("sys_id"));
- }
- for(var count=0;count < item_access.length; count++){
- gs.log(item_access[count].name);
- }
Hope that helps.
Thanks,
Mandar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 07:44 AM
Hi Aditya,
It's mostly because the reference is not treated as a string but rather as a glide element.
You can use the order.getValue("sys_id"); to avoid getting same repeated value.
- var order=new GlideRecord('sc_cat_item');
- order.addQuery('category.title','Computer & Telephony');
- order.addActiveQuery();
- order.query();
- var item_access = [];
- while(order.next()){
- item_access.push(order.getValue("sys_id"));
- }
- for(var count=0;count < item_access.length; count++){
- gs.log(item_access[count].name);
- }
Hope that helps.
Thanks,
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 07:03 AM
Hello,
Sorry to re-open this feed long time after, but I have same issue than Adityasaraf.
Your solution doesn't work for me as it save the sys_id as string. I loose the reference to the GlideRecord and are not able to retrieve record properties later.
Here is what I got with following code :
Do you have any other idea? I wanted to avoid creating new query to table via new GlideRecord record using get method as follow :
Thanks for answer! 😊
Best regards,
Fabien