- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2016 02:58 AM
How to get a list of unique values of a field of a partiular table
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2016 03:34 AM
Hi Surya,
Something like this would do it. I would recommend caution when running queries on task as the table can be very large and could cause performance issues.
var gr = new GlideAggregate("task");
gr.addAggregate("COUNT");
gr.groupBy("cmdb_ci");
gr.query();
while (gr.next()) {
gs.print(gr.getAggregate("COUNT") + " -- " + gr.getValue("cmdb_ci") + " -- " + gr.getDisplayValue("cmdb_ci"));
}
Does this help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2016 03:34 AM
Hi Surya,
Something like this would do it. I would recommend caution when running queries on task as the table can be very large and could cause performance issues.
var gr = new GlideAggregate("task");
gr.addAggregate("COUNT");
gr.groupBy("cmdb_ci");
gr.query();
while (gr.next()) {
gs.print(gr.getAggregate("COUNT") + " -- " + gr.getValue("cmdb_ci") + " -- " + gr.getDisplayValue("cmdb_ci"));
}
Does this help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2016 04:27 AM
Hi Richard,
Is there a way I can get the list as comma separated values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2016 06:32 AM
You'll need to build it up yourself while iterating over the GlideRecord.
I would use an push each item onto an array and then join the array. Something like this:
var idArr = [];
var gr = new GlideAggregate("task");
gr.addNotNullQuery("cmdb_ci");
gr.addAggregate("COUNT");
gr.groupBy("cmdb_ci");
gr.query();
while (gr.next()) {
idArr.push(gr.getValue("cmdb_ci"));
}
gs.print(idArr.join(","));
In line 12 I use the join function which returns a String representation of the Array delimited by a comma.
Thanks,
Cameron