Skip to content

Commit 6ca690c

Browse files
emailAttachment.js
1 parent 6c917c2 commit 6ca690c

File tree

1 file changed

+27
-0
lines changed
  • Server-Side Components/Server Side/Generate Attachment and add it to the email

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
2+
/* Optional EmailOutbound */
3+
email, /* Optional GlideRecord */ email_action,
4+
/* Optional GlideRecord */
5+
event) {
6+
7+
var Headers = ["Number", "Caller", "Short Desc", "Assignment Group", "Assigned To"];
8+
var currentDate = new GlideDateTime();
9+
var fileName = 'Incidents' + '.csv';
10+
var csvData = ''; //The variable csvData will contain a string which is used to build the CSV file contents
11+
for (var i = 0; i < Headers.length; i++) { //Build the Headers
12+
csvData = csvData + '"' + Headers[i] + '"' + ',';
13+
}
14+
csvData = csvData + "\r\n";
15+
16+
var gr = new GlideRecord("incident");
17+
gr.addActiveQuery();
18+
gr.query();
19+
while (gr.next()) {
20+
csvData = csvData + '"' + gr.number + '",' + '"' + gr.caller_id.getDisplayValue() + '",' + '"' + gr.short_description + '",' + '"' + gr.assignment_group.getDisplayValue() + '",' + '"' + gr.assigned_to.getDisplayValue() + '"';
21+
csvData = csvData + "\r\n";
22+
}
23+
24+
var grAttachment = new GlideSysAttachment();
25+
grAttachment.write(event, fileName, 'application/csv', csvData);
26+
27+
})(current, template, email, email_action, event);

0 commit comments

Comments
 (0)