質問編集履歴

1

頂いた回答で試したコードと、フォームの回答形式を追加しました。

2023/04/12 02:10

投稿

CH-SMAROP164
CH-SMAROP164

スコア2

test CHANGED
File without changes
test CHANGED
@@ -9,22 +9,29 @@
9
9
  ### 前提
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
+
12
- TypeError: Cannot read properties of undefined (reading 'values') gs2
13
+ TypeError: Cannot read properties of undefined (reading 'response') gs4
14
+
13
15
 
14
16
  ### 該当のソースコード
15
- function createEvent(e) {
17
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-04-12/019be17b-373c-4a89-9f00-442814102005.png)function createEvent(e) {
16
- let [timestamp, date, time1, time2] = e.values;
18
+ // let [timestamp, date, time1, time2] = e.values;
19
+ const items = [];
20
+ const itemResponses = e.response.getItemResponses();
21
+ for (const itemResponse of itemResponses) {
22
+ items.push(itemResponse.getResponse());
23
+ }
24
+ let [date, time1, time2] = items;
17
- let id = 'xxxxxxxxxxxxxxxxxxxxxxxx@group.calendar.google.com';
25
+ let id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@group.calendar.google.com';
18
- let Calendar = CalendarApp.getCalendarById(id);
26
+ let calendar = CalendarApp.getCalendarById(id);
19
- let title = `xxx薬局`;
27
+ let title = `xxx薬局`;
20
28
 
21
- let y = Number(date.split('年')[0]);
22
- let m = Number(date.split('年')[1].split('月')[0]) - 1;
23
- let d = Number(date.split('月')[1].split('日')[0]);
24
- let hours = Number(time1,time2.split(':')[0]);
29
+ let hoursS = Number(time1.split(':')[0]);
25
- let minutes = Number(time1,time2.split(':')[1]);
30
+ let minutesS = Number(time1.split(':')[1]);
31
+ let hoursE = Number(time2.split(':')[0]);
32
+ let minutesE = Number(time2.split(':')[1]);
26
- let startTime = new Date(y, m, d, hours, minutes);
33
+ let startTime = new Date(y, m, d, hoursS, minutesS);
27
- let endTime = new Date(y, m, d, hours, minutes);
34
+ let endTime = new Date(y, m, d, hoursE, minutesE);
28
35
 
29
36
  `▼勤務内容
30
37
  予約日時:${timestamp}
@@ -32,7 +39,7 @@
32
39
  開始時間: ${time1}
33
40
  終了時間: ${time2}`;
34
41
 
35
- CalendarApps.createEvent(title, startTime, endTime, options);
42
+ Calendar.createEvent(title, startTime, endTime);
36
43
  }
37
44
 
38
45