- Mastering ServiceNow Scripting
- Andrew Kindred
- 145字
- 2021-06-24 19:08:39
GlideAggregate
The GlideAggregate class is an extension of GlideRecord and works in a similar way. The difference is that GlideRecord tends to give you database objects whereas GlideAggregate deals in counts and numbers.
We'll take a quick look at how GlideAggregate works:
var counter = new GlideAggregate('incident');
counter.addAggregate('COUNT');
counter.query();
if (counter.next()) {
var noOfIncidents = counter.getAggregate('COUNT');
}
This first example will give us the number of incidents in the database and place it in the noOfIncidents field. We can add addQuery lines in exactly the same way we would for GlideRecord if we wanted to reduce the number of incident records we returned.
As well as COUNT, we can also use SUM, MAX, MIN, and AVG to get the total sum, maximum number, minimum number, and average, respectively.
I don't find GlideAggregate used that regularly, but it is an efficient way to count records.
推薦閱讀
- 繪制進程圖:可視化D++語言(第1冊)
- 32位嵌入式系統與SoC設計導論
- 我的J2EE成功之路
- Design for the Future
- Cloud Analytics with Microsoft Azure
- 精通Windows Vista必讀
- Julia 1.0 Programming
- 大數據處理平臺
- Machine Learning with the Elastic Stack
- Python:Data Analytics and Visualization
- Excel 2007常見技法與行業應用實例精講
- Chef:Powerful Infrastructure Automation
- DevOps Bootcamp
- 氣動系統裝調與PLC控制
- 貫通Hibernate開發