Hi, how can i generate weekly report to send to mail?

Sachin65
Tera Expert

Hi , Run automated script for every for week and generate a reports to send to mail automatically. 

Requirment: in cmdb table weekly how many records added this reports automatically send to mail  how can i do this can please help me on this?    

4 REPLIES 4

Shishir Srivast
Mega Sage

you can use the schedule option on report to schedule it on weekly basis to trigger an email.

find_real_file.png

 

find_real_file.png

 

prasiyalraj
Giga Expert

Hi Sachin,

 

In Reports > Go to Scheduled Reports.Scheduled it As your requirement.

 

Thanks

Prasiyal

manali harmalka
Kilo Guru

Hi Sachin,

Please check below link for genetation of weekly report to send to email,

 

 https://docs.servicenow.com/bundle/geneva-performance-analytics-and-reporting/page/use/advanced_repo...

This is you can use for sending email statically.

 

can you tell how you need to send reports?statically or dynamically?

Nikhil Dixit
Giga Expert

Hi Sachin,

 

The reporting engine is easy to work with and allows users to create simple reports very easily. Using Email Notifications as a way to create custom reports.

It's a fairly simple way to deliver data in a format that you have complete control over and is often overlooked.   The output can be quite simple or very elaborate, with multiple colors to highlight high priority items, different typefaces and sizes, etc...  

You have the full power of HTML at your fingertips.   Please go through with the sample example as mention below for a custom report.

 

Step 1, create an Event that will trigger the Email Notification:

Event.png

 

Step 2, create a Scheduled Script Execution record that will raise the event.   Select the System Definition \ Scheduled Jobs module and click on the "New" button at the top of the list.   Select "Automatically run a script of your choosing" on the Interceptor page:

Interceptor.png

 

...and then create the following record:

Script.png

 

The script will run everyday at 7:00 am, and if it is Monday - Friday, will raise the event we created.   The event will trigger the email notification we will create next:

Notification.png

Select "Event is fired" in the "Send when" drop down and select the new event we created in the "Event name" field.   I have not set any conditions in this example, but you could, for example, perform a check to see if any records meet your criteria before creating the report.   I prefer to add a message in the report itself to signify no records were found in order to avoid any confusion - it really depends on the audience and content of the report.

 

You will want to select the "Send to event creator" check box on the "Who will receive" tab/section while you are testing this out to make sure you receive the emails, otherwise you will never get them and end up blaming me.       You may have to select the "Advanced view" Related Link in order to see it.

 

The secret to the solution is found in the "Message" field on the "What it will contain" tab/section.   This is where we use some mail_script code to get the data and output it in the format we want:

 

The following active Incidents were created at least 7 days ago:

 

<mail_script>

      baseUrl = gs.getProperty("glide.servlet.uri");

      var gr = new GlideRecord("incident");

      gr.addEncodedQuery("active=true^sys_created_onBETWEENjavascript:gs.daysAgoEnd(13)@javascript:gs.daysAgoStart(7)");

      gr.orderBy('sys_created_on');

      gr.query();

      if (gr.hasNext()) {

              template.print("<br/><br/><br/>Within 7 - 13 days:<br/>");

              while (gr.next()) {

                      template.print(gr.getDisplayValue('sys_created_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + gr.short_description + "<br/>");

              }

      }

 

      var gr = new GlideRecord("incident");

      gr.addEncodedQuery("active=true^sys_created_onBETWEENjavascript:gs.daysAgoEnd(29)@javascript:gs.daysAgoStart(14)");

      gr.orderBy('sys_created_on');

      gr.query();

      if (gr.hasNext()) {

              template.print("<br/><br/><br/>Within 14 - 29 days:<br/>");

              while (gr.next()) {

                      template.print(gr.getDisplayValue('sys_created_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + gr.short_description + "<br/>");

              }

      }

 

      var gr = new GlideRecord("incident");

      gr.addEncodedQuery("active=true^sys_created_onBETWEENjavascript:gs.daysAgoEnd(59)@javascript:gs.daysAgoStart(30)");

      gr.orderBy('sys_created_on');

      gr.query();

      if (gr.hasNext()) {

              template.print("<br/><br/><br/>Within 30 - 59 days:<br/>");

              while (gr.next()) {

                      template.print(gr.getDisplayValue('sys_created_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + gr.short_description + "<br/>");

              }

      }

 

      var gr = new GlideRecord("incident");

      gr.addEncodedQuery("active=true^sys_created_on<javascript:gs.daysAgoStart(60)");

      gr.orderBy('sys_created_on');

      gr.query();

      if (gr.hasNext()) {

              template.print("<br/><br/><br/>60 days or more:<br/>");

              while (gr.next()) {

                      template.print(gr.getDisplayValue('sys_created_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + gr.short_description + "<br/>");

              }

      }

</mail_script>

 

UPDATED December 20, 2017: I've removed the "gr.setLimit(x)" lines in the script as they were originally in there just for testing purposes.   They were limiting the number of records returned by the query.

 

 

The script performs a few queries and outputs the results, grouping the results based on the creation date:

IncidentEmail.png

 

Here's another example:

KBNotification.png

 

Not fancy, but gets the job done.   All self-contained within the email without any unnecessary attachments.

 

The examples I've shown are pretty basic, Makes for a real nice looking and effective report, all within the same platform.   Easy to setup, can be tricky getting the proper format for your output, but worthwhile taking a look at, I believe.

 

Thanks,

Nikhil Dixit