Using GlideAggregate group by Month

hloredo
Kilo Explorer

Hello, I'm trying to get a list of created and close incidents by month using the GlideAggregate object. The same you'd get creating a trend report.

I've tried to set a trend and then an aggregate:

var trend = new GlideAggregate('incident');
trend.setTrend ('opened_at','Month');
trend.addAggregate('COUNT');
trend.query();

so far, it seems that the setTrend method does nothing as I'm getting just one record with the count of all the incidents.

How the setTrend method must be used? Couldn't find any example in the wiki. How can I access the Month value from the query results?

Thanks in advance

6 REPLIES 6

Not applicable

I think you might want trend.setGroup(false).



var trend = new GlideAggregate('incident');
trend.addTrend ('opened_at','Month');
trend.addAggregate('COUNT');
trend.setGroup(false);
trend.query();
while(trend.next()) {
gs.print(trend.getValue('timeref') + ': ' + trend.getAggregate('COUNT'));
}


(took me a while to work out how to get the time base. We don't seem to have that documented.)


hloredo
Kilo Explorer

Thank you very much, setting the setGroup property to false did the trick.

It would be very useful to include examples of all GlideAggregate methods in the Wiki.

Cheers


Thank you. I'm curious to know how did you come up with this, as there is no documentation?


Hi James,




It was helpful to get the trend value from using 'timeref' in getValue method. However; there is another reference variable 'yearref', whose value was fetched as null using the getValue method. Also, the timeref returns the output as "year/year". How can we get the "yearref" value ?