Including Record Count in Scheduled Report Email

BibekP
Tera Contributor

Hello Team,

I have created and scheduled a report. I would like to include the number of records in the email body. Could you please advise on how to achieve this?

1 ACCEPTED SOLUTION

priyatam_pvp
Tera Guru

ServiceNow’s Scheduled Reports do not natively provide a way to include a record count in the email body, you can achieve this using the below code in the mail script change table name and filters:

Mail script :

var gr = new GlideAggregate('incident'); // Change table name as needed

gr.addQuery('active', true); // Apply your conditions

gr.addAggregate('COUNT');

gr.query();

 

var recordCount = 0;

if (gr.next()) {

    recordCount = gr.getAggregate('COUNT');

}

Please Mark this helpful

Regards
Priyatam

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @BibekP 

 

https://www.servicenow.com/community/performance-analytics-forum/how-to-add-number-of-cis-count-in-e...

https://www.servicenow.com/community/performance-analytics-forum/how-to-add-number-of-cis-count-in-e...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

priyatam_pvp
Tera Guru

ServiceNow’s Scheduled Reports do not natively provide a way to include a record count in the email body, you can achieve this using the below code in the mail script change table name and filters:

Mail script :

var gr = new GlideAggregate('incident'); // Change table name as needed

gr.addQuery('active', true); // Apply your conditions

gr.addAggregate('COUNT');

gr.query();

 

var recordCount = 0;

if (gr.next()) {

    recordCount = gr.getAggregate('COUNT');

}

Please Mark this helpful

Regards
Priyatam

Ankur Bawiskar
Tera Patron
Tera Patron

@BibekP 

you can use email script in scheduled email body and print the record count based on your report filter conditions

Scheduling a report with an inline table in mail body with the attachments 

Embed List Reports in a Scheduled Report Email 

Scheduling a report for dynamic Recipients based on the table column of the report 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Shivalika
Mega Sage

Hello @BibekP 

 

Last I tried, score based report was not generating any attachment in the email that was scheduled. 

 

So it's better to go via script and show the count in the email body. Mail script would work in this scenario definitely. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY