Row count

sasi
Tera Contributor

Hi,

i want Row count by using glide object. please explain me with the script.

 

Thanks.

1 ACCEPTED SOLUTION

Ritanjali Pati
Mega Expert

Hi Sasi,

To test your code go to navigator-->Background script and run the following script: 

var gr=new GlideRecord("incident"); //glide the table you want to count rows


gr.addQuery('active', true); //shows all active records
gr.query(); // query the condition

 gs.print(gr.getRowCount()); // counts all the active incidents and prints the number


while(gr.next())
{
gs.print(gr.number);
}

 

If you got the satisfied answer please mark my answer as correct and helpful.

 

Thanks,

Ritanjali, www.dxsherpa.com

View solution in original post

6 REPLIES 6

Ritanjali Pati
Mega Expert

Hi Sasi,

To test your code go to navigator-->Background script and run the following script: 

var gr=new GlideRecord("incident"); //glide the table you want to count rows


gr.addQuery('active', true); //shows all active records
gr.query(); // query the condition

 gs.print(gr.getRowCount()); // counts all the active incidents and prints the number


while(gr.next())
{
gs.print(gr.number);
}

 

If you got the satisfied answer please mark my answer as correct and helpful.

 

Thanks,

Ritanjali, www.dxsherpa.com

Jaydeep Parmar
Kilo Guru

Use GlideAggregate for Simple Record Counting

If you need to count rows, you have two options: the getRowCount() method from GlideRecord, or GlideAggregate. Using GlideRecord to count rows can cause scalability issues as tables grow over time, because it retrieves every record with the query and then counts them. GlideAggregate gets its result from built-in database functionality, which is much quicker and doesn’t suffer from the scalability issues that GlideRecord does.

For more details refer this,

https://developer.servicenow.com/app.do#!/document/content/app_store_doc_technical_best_practices_ja...

Read this for GlideAggregate concept

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