Is there any way to count the total number of records in a table?

brittanyeccles
Giga Contributor

Is there any way to count the total number of records in a specific table? It doesn't have to have a certain field, I just want to count the total number of records.

I have already tried to use the following, but neither of them worked:

var count = new GlideAggregate('tableName');

count.addAggreate('COUNT');

count.query();

var records = 0;

if (count.next())

{

        records = count.getAggregate('COUNT');

}

and also:

var grCount = new GlideRecord('tableName');

grCount.query();

var count = 0;

while (grCount.next())

{

        count++;

}

6 REPLIES 6

Thank you for taking the time to reply! However, when I tried to use this I'm getting the same error as I did previously which says "GlideAggregate is not defined." (it says this in the console) Do you have an idea as to why it would say this?


If you are writing this on a Client Script, you will have to use GlideAjax. Check the below link.



Re: How to use glideAggregate in client script



Please mark this response as correct or helpful if it assisted you with your question.