回答編集履歴
1
a
test
CHANGED
@@ -1,9 +1,169 @@
|
|
1
|
-
|
1
|
+
```javascript
|
2
2
|
|
3
|
+
/* 仕様とされるもの @ 参考サイト。一部補正
|
3
4
|
|
5
|
+
・「依頼者」C列を入力すると、自動で「依頼日」D列が挿入される
|
4
6
|
|
5
|
-
|
7
|
+
・「担当者」F列を入力すると、自動で担当者にメール通知される(と仕様には書いてあるが嘘で、担当者を入れると、G列が、通知予定になって、通知予定のやつを定期的に送信する)
|
6
8
|
|
9
|
+
→ 嘘にせず、仕様のとおりその場で送信すればいい
|
7
10
|
|
11
|
+
・「対応内容」H列を入力すると、自動で「対応日」I列が挿入される
|
8
12
|
|
13
|
+
・ステータスB列を「完了」にすると、完了にしたレコード(1行全て)の背景色が自動でグレーに変わる
|
14
|
+
|
15
|
+
*/
|
16
|
+
|
17
|
+
function getOnEditTasks(col) {
|
18
|
+
|
19
|
+
const tasks = {
|
20
|
+
|
21
|
+
2 : [gen_setRowBackground("grey")],
|
22
|
+
|
23
|
+
3 : [gen_setValue(0,1, new Date())],
|
24
|
+
|
25
|
+
6 : [gen_sendMail(0,1) /*,gen_setValue(0,1, "通知予定")*/],
|
26
|
+
|
27
|
+
8 : [gen_setValue(0,1, new Date())]
|
28
|
+
|
29
|
+
};
|
30
|
+
|
31
|
+
const ret = tasks[col];
|
32
|
+
|
33
|
+
return ret !== undefined ? ret : [] ;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
function getMailAddress(name) {
|
38
|
+
|
39
|
+
const namelist = {
|
40
|
+
|
41
|
+
"a" : "root@example.com"
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
const addr = namelist[name];
|
46
|
+
|
47
|
+
return addr === undefined ? "" : addr ;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
function onEditTrigger(e) {
|
52
|
+
|
53
|
+
const targetSheet = "シート1";
|
54
|
+
|
55
|
+
if(e.range.getSheet().getName() !== targetSheet) return;
|
56
|
+
|
57
|
+
const c = e.range.getColumn();
|
58
|
+
|
59
|
+
getOnEditTasks(c).forEach(function (f) {
|
60
|
+
|
61
|
+
f(e);
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
function gen_setValue(offsetR, offsetC, value) {
|
68
|
+
|
69
|
+
return function(e) {
|
70
|
+
|
71
|
+
e.range.offset(offsetR, offsetC).setValue(value);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
function gen_setRowBackground(colour) {
|
78
|
+
|
79
|
+
return function(e) {
|
80
|
+
|
81
|
+
const fin = "完了";
|
82
|
+
|
83
|
+
if(e.value !== fin) return;
|
84
|
+
|
85
|
+
const sheet = e.range.getSheet();
|
86
|
+
|
87
|
+
const c = sheet.getMaxColumns();
|
88
|
+
|
89
|
+
sheet.getRange(e.range.getRow(), 1, 1, c).setBackground(colour);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
function gen_sendMail(offsetR, offsetC) {
|
96
|
+
|
97
|
+
return function(e) {
|
98
|
+
|
99
|
+
const errNotify = "通知失敗";
|
100
|
+
|
101
|
+
const doneNotify = "通知済";
|
102
|
+
|
103
|
+
const name = e.value;
|
104
|
+
|
105
|
+
if(name === undefined) { e.range.offset(offsetR, offsetC).setValue(errNotify); return; }
|
106
|
+
|
107
|
+
const addr = getMailAddress(name);
|
108
|
+
|
9
|
-
|
109
|
+
if(addr === "") { e.range.offset(offsetR, offsetC).setValue(errNotify); return; }
|
110
|
+
|
111
|
+
notificationSendEmail(addr, name);
|
112
|
+
|
113
|
+
e.range.offset(offsetR, offsetC).setValue(doneNotify);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
function notificationSendEmail(to,name){
|
120
|
+
|
121
|
+
const taskAdded = "タスクが追加されました";
|
122
|
+
|
123
|
+
GmailApp.sendEmail(to,taskAdded ,name + '様\n\n' + taskAdded);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
/*
|
128
|
+
|
129
|
+
function timerTrigger() {
|
130
|
+
|
131
|
+
const targetSheet = "シート1";
|
132
|
+
|
133
|
+
const colF = 6;
|
134
|
+
|
135
|
+
const colG = 7;
|
136
|
+
|
137
|
+
const willNotify = "通知予定";
|
138
|
+
|
139
|
+
const errNotify = "通知失敗";
|
140
|
+
|
141
|
+
const doneNotify = "通知済";
|
142
|
+
|
143
|
+
const range = SpreadsheetApp.getActive().getSheetByName(targetSheet).getDataRange();
|
144
|
+
|
145
|
+
const dat = rang.getValues().map(function(e){
|
146
|
+
|
147
|
+
if(e[colG - 1] !== willNotify) return e;
|
148
|
+
|
149
|
+
const addr = getMailAddress(e[colF - 1]);
|
150
|
+
|
151
|
+
if(addr === "") { e[colG - 1] = errNotify; return e; }
|
152
|
+
|
153
|
+
notificationSendEmail(addr, e[colF - 1]);
|
154
|
+
|
155
|
+
e[colG - 1] = doneNotify;
|
156
|
+
|
157
|
+
return e;
|
158
|
+
|
159
|
+
});
|
160
|
+
|
161
|
+
range.setValues(dat);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
*/
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
onEditTrigger を編集時トリガーとして登録します。
|