How to get a list of unique values of a field of a partiular table

surya123
Mega Guru

How to get a list of unique values of a field of a partiular table

1 ACCEPTED SOLUTION

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?


View solution in original post

7 REPLIES 7

Kaka Nayeem
Tera Guru

Hi Surya,


          Can you elaborate?



Thanks,


Kaka Nayeem


cameronrichard
ServiceNow Employee
ServiceNow Employee

Hello Surya,



You can use GlideAggregate to do so.



https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&type=server&scoped=false&to=class__unsc...



I can give you a hand if you give more a little more info on the table structure.



Thanks,



Cameron


I want to get a list of unique CI which are used in task table.


Since a single CI has been used in many task records, i want to get a list of unique Ci used there


Yes you can use GlideAggregate. and use groupBy on CI field.


Search for "GlideAggregate" in wiki to get more details.