Array elements Glideaggregate

JG16
Tera Contributor

Hi,

I am doing like this 

var ga = new GlideAggregate(theTable);
    ga.addAggregate('COUNT', dpField);
    ga.addHaving('COUNT', dpField, '>', '1');
    ga.query(); 
    var arDupes = new Array();
    while (ga.next()) { 
      arDupes.push(ga.getValue(dpField));    
    }
  Unfortunately I am getting all array elements are same and last value.
But if I put his.info then it is logging different values.

Please help me why is this behaviour ?

 

Thanks 

JG

 

 

1 ACCEPTED SOLUTION

Abhishek Pidwa
Kilo Guru

I believe you meant when you do gs.addInfoMessage(ga.getValue(dpField)) you are getting different values ? 

 

In such case just modify your line of code from 

 

var arDupes = new Array(); 

 

to 

var arDupes = [];

 

Try this and let me know what you get after iterating through the array ?

 

View solution in original post

5 REPLIES 5

Abhishek Pidwa
Kilo Guru

I believe you meant when you do gs.addInfoMessage(ga.getValue(dpField)) you are getting different values ? 

 

In such case just modify your line of code from 

 

var arDupes = new Array(); 

 

to 

var arDupes = [];

 

Try this and let me know what you get after iterating through the array ?

 

Chalan B L
Giga Guru

Hello JG,

GlideAggregate

GlideAggregate examples

-----------Executed in BackGround Script-------------------------

var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT','category');
ga.addHaving('COUNT', 'category', '>', '1');
ga.query();
var arDupes = [];
while (ga.next()) {


arDupes.push(ga.getValue('category'));
}

gs.print(arDupes);

-------output---------------------

*** Script: database,hardware,inquiry,network,software

--------------------------------


Mark answer as correct and helpful if it helped you..!!

Regards,
Chalan

JG16
Tera Contributor
@abhishek - I tried the way you suggested but still it is showing same element.. also I have cleared browser cache and tried, still same. Yes if I do gs.info it prints different values.

Hey JG, 

 

What exactly are you trying to do and how are you doing it ? Can you help us with an example ?

 

Unfortunately I am getting all array elements are same and last value.
But if I put his.info then it is logging different values.

How are you printing the array elements ? Can you walk us through the exact code ?