-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.gs
89 lines (79 loc) · 2.32 KB
/
Code.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function testSchemas() {
var threads = GmailApp.search('from:"[email protected]"');
//var threads = GmailApp.getInboxThreads(0, 2);
var label = GmailApp.getUserLabelByName("Verificado");
var ssNew = SpreadsheetApp.create("Listado de Tareas", 100, 17);
skin(ssNew);
for (var i = 0; i < threads.length; i++) {
var threads = threads[i];
var messages = threads.getMessages();
var solution = "";
var dateSolution = "";
for (var i = 0; i < messages.length; i++) {
solution = messages[i].getBody();
dateSolution = messages[i].getDate();
Logger.log(messages[i].getSubject());
}
Logger.log(threads.getFirstMessageSubject());
var obj = {
"subject": threads.getFirstMessageSubject(),
"date": threads.getLastMessageDate(),
"label": threads.getLabels()[0].getName(),
"solution": solution,
"dateSolution": dateSolution,
"parent": threads
}
threads.addLabel(label)
insertData(ssNew,obj);
}
SpreadsheetApp.flush();
var file = DriveApp.getFileById(ssNew.getId());
var url = file.getUrl()
var mineType = file.getMimeType();
GmailApp.sendEmail(Session.getActiveUser().getEmail(), 'Verificador de Tareas', 'Adjunto el pdf por favor verifique el documento en Drive: '+ url, {
attachments: [file],
name: 'Verificador de Tareas'
});
function insertData(sheet,obj) {
sheet.appendRow([
"",
"Finalizado",
"",
obj.date.getMonth(),
obj.date,
obj.subject,
Session.getActiveUser().getEmail(),
"",
"",
obj.solution,
obj.label,
"Tipo Error",
obj.dateSolution,
obj.dateSolution,
obj.date-obj.dateSolution,
]);
}
function skin(ssNew) {
ssNew.appendRow([
"No. Ticket",
"Estado",
"Usuario Aplicación",
"MES",
"Fecha llegada Soporte",
"Descripción Problema",
"Ingeniero Responsable",
"Fecha Estim Entrega",
"Hora Estim Entrega",
"Descripción Solución",
"Observación Sistemas",
"Tipo Error",
"Fecha Entreg",
"Hora Entrega",
"Tiempo Tarea"
]);
ssNew.setColumnWidth(1, 200);
ssNew.setColumnWidth(2, 200);
var sheet = ssNew.getSheets()[0];
sheet.getRange("A1:O1").setFontWeight("bold").setHorizontalAlignment("center");;
}
}