Skip to content

Commit 4f46a74

Browse files
Hactober fest 2025 (4th pull request) (#2523)
* code_snippet.js * README.md * Add files via upload * code_snippet.js * README.md
1 parent 4311771 commit 4f46a74

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This code_snippet.js script export incidents of the last 7 days and email the CSV.
2+
This script will be created as Scheduled Script.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Below script export incidents of the last 7 days and email the CSV using Scheduled Script
2+
var fileName = 'incident_export_' + gs.nowDateTime() + '.csv';
3+
var csv = 'Number,Short Description,Priority\n';
4+
var gr = new GlideRecord('incident');
5+
gr.addQuery('opened_at', '>=', gs.daysAgoStart(7));
6+
gr.query();
7+
while (gr.next()) {
8+
csv += gr.number + ',' + gr.short_description + ',' + gr.priority + '\n';
9+
}
10+
var attachment = new GlideSysAttachment();
11+
attachment.write('incident', '', fileName, csv);
12+
gs.eventQueue('csv.report.ready', null, fileName, gs.getUserID());

0 commit comments

Comments
 (0)