Get Count / Number of Records in Current List View

G24
Kilo Sage

Hello experts.

I have a magical List View which looks like this:

ListView.png

In my UI Action, how do I get access to the total number (82) of records in the List View?  I'm not seeing a Count property on the GlideList (g_list) object.  What am I missing?

 

I want to display a client-side confirmation message which says "Are you SURE you want to do X to all 82 records you shown below?"

Thanks.

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@G24 Tried and tested solution.

 

You can use below line

g_list.grandTotalRows

 

The above line will return you 82.

 

Result:

jaheerhattiwale_0-1672194840917.png

 

UI Action:

jaheerhattiwale_1-1672194866294.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

4 REPLIES 4

jaheerhattiwale
Mega Sage
Mega Sage

@G24 Tried and tested solution.

 

You can use below line

g_list.grandTotalRows

 

The above line will return you 82.

 

Result:

jaheerhattiwale_0-1672194840917.png

 

UI Action:

jaheerhattiwale_1-1672194866294.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale That is fantastic!  Although I'm a little unclear on the difference between "totalRows" and "grandTotalRows".  I was on a List View showing 10 of 15 records, and BOTH of those variables returned 15.

 

Also, do you know why I am not seeing those g_list properties documented here ?  Thanks!!

@G24 I too saw that both functions returning same number. I did not test that.

 

You can add below line in client script to see the g_list object in console.

console.log(g_list);

 

Do CTRL + Shift + i to open console and see result.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

From my testing, it looks like you will see a difference when you've grouped the rows in your list. 

grandTotalRows will give you the count of all of the records from the query
totalRows seems to show the count of the rows shown in the list. 
For example, you have a query that returns 2000 CI records and then you group it by Support group, which results in 15 group rows. grandTotalRows will return 2000, while totalRows will return the 15. if you aren't grouping, I would expect them to return the same number