Generate a weekly incident report (CSV attachment) for incidents created during the one-week

Mannam Praveen
Tera Expert

Generate a weekly incident report (CSV attachment) for incidents created during the one-week window from last Friday 09:00 AM up to this Friday 09:00 AM, and email filtered attachments to recipients based on Category / Sub-category rules.

or incidents created within the date window, group and send attachments based on the following Category/Sub-category rules:

  1. Category = Network AND Sub-category = DNS

  2. Category = Network AND Sub-category = VPN

  3. Category = Hardware AND Sub-category = CPU

Notes: Each recipient should receive only the incidents that match their rule (i.e., one CSV per recipient containing only their matching records).

 

How we can acheive it. we dont want to use scheduled reports for this 

 

3 REPLIES 3

MadhanMaddy
Giga Contributor

Hi @Mannam Praveen  ,

 

You can use Scheduled jobs & write a script to generate CSV file using below script. 

You can also use Flow designer to run periodically. 

    var csv = [];
    var headers = ['Number', 'Short Description', 'Category', 'Subcategory', 'Opened'];
    csv.push(headers.join(','));

    var gr = new GlideRecord('table_name');
    gr.addQuery('Query');
    gr.query();
    
    while (gr.next()) {
        var row = [];
        row.push(gr.getValue('number'));
        row.push('gr.getValue('short_description');
        row.push(gr.getValue('category'));
        row.push(gr.getValue('subcategory'));
        row.push(gr.getValue('sys_created_on'));
        csv.push(row.join(','));
    }
    
    var csvString = csv.join('\n');
  
    var grFile = new GlideRecord('sys_attachment');
    grFile.initialize();
    var attachment = new GlideSysAttachment();
    attachment.write('incident', '', 'incident_report.csv', csvString);

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards,
Madhan

Thanks for script but how I can attach csv file notification and send through notification. Because here we have multiple conditions 

Hi @Mannam Praveen  ,

 

Using event you can pass it on to the notification & trigger it from there or if you're triggering from any record directly you can say include attachments & this attachment generated above will be used to send it. 
In my case we're first attaching the attachment generated on RITM & changing the state using the same script so a notification will be triggered and automatically include our attachment added.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards,
Madhan