Scheduled reports

Vaishali 11
Tera Guru

I have 2 scheduled reports on incident & ritm table respectively and the data is sent through excel format. The user wants that the records which are there in the excel can also be seen in the email body.

Is that feasible to do? If yes, how can it be done?

 

 

Thanks in advance!!

2 ACCEPTED SOLUTIONS

System Notificaiton >> Email >> Mail script

(function runMailScript(current, template, email, email_action, event) {

         var inci=new GlideRecord('incident');
		 //inci.addQuery('')//pass relevant query here as per report
		 inci.query();
		 template.print('Inci count is '+inci.getRowCount());
		 
		 }

})(current, template, email, email_action, event);

 

Call mail script in format

${mail_script:getcountofrecords}

View solution in original post

Hello @Vaishali 11 ,

You can actually write an email script for this to fetch the count of the records .

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here

 var gr = new GlideRecord('sc_req_item');
 gr.addQuery('active',true);
 gr.query();

 template.print ("RITM Count "+ gr.getRowCount());


 var inc = new GlideRecord('incident');
 inc.addQuery('active',true);
 inc.query();

 template.print ("Incident Count "+ inc.getRowCount());

 
})(current, template, email, email_action, event);

Screenshot 2023-08-11 at 17.49.47.png

 

Also call the email script in the notification

Screenshot 2023-08-11 at 18.34.30.png

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 

 

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Vaishali 11 

Not a good practice and not at all recommended.

if they are already receiving the file why to send the same data in email body.

Consider the excel contains 100-400 records satisfying the report condition how the email will look with data for those 100-400 records

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

Jaspal Singh
Mega Patron
Mega Patron

Hi Vaishali,

 

Did you try to check the reason for it? What if scheduled reports has hundered or thousands of records? The body of the notification will explode. 

If you still want, you can write a mail script & call the mail script in the scheduled report to get it worked.

Vaishali 11
Tera Guru

There is a slight change in the requirement. The user now wants only  the count of the records(that are sent through the excel) in the email body.

How this can be done?

 

Thanks in advance!!

You still need mail script to be in place & you can return the count using GlideRecord in the mail script.