The CreatorCon Call for Content is officially open! Get started here.

getRowCount not working in my BR?

Ashirav
Tera Expert

Hi,

I want to display a message if the list view is blank for a table, but my message shows even if the table is not blank because getRowCount is giving the wrong result.

For this I have written a before-query BR:-

(function executeRule(current, previous /*null when async*/) {

var index = gs.action.getGlideURI().toString().indexOf('kb_knowledge_list'); //It checks for list view, i.e. "_list" is there in UR L if the List view appears


var count = current.getRowCount();
gs.addInfoMessage(count);
if(index != -1 && count == 0)
{
var c='No matches found for the search item';
gs.addInfoMessage(c);

}
else
{}

})(current, previous);

 

When the table is not blank, the value of "count" is still 0, and if the table is blank, the count is still 0.

Please help.

1 ACCEPTED SOLUTION

This function doesn't work with current, so simply define a GlideRecord to kb_knowledge table adding the query as per your need:

var gr = new GlideRecord('kb_knowledge');
gr.addQuery(<add your condition>);
gr.query();
var count = gr.getRowCount());

View solution in original post

11 REPLIES 11

Harsh Vardhan
Giga Patron

i think getRowCount() will not work with current object. do glide record and then use your glide record object to fetch the row count. 

 

doc link for furthe details. 

 

https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_ScopedGlideRecordGetRowCount

Hi,

But i have created this BR on the kb_knowledge table. So why does "current" not work with getRowCount as the "current" refers to the table on which the BR is based?

Hi Ashirav,

getRowCount() works after applying some query to the table using gliderecord etc

since no query is getting applied it won't work

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

current is an object which refer to the current form, but getRowCount() actually works when you are doing glide record on your table to get the list of rows. so you must have to do gliderecord here.