実現したいこと
Googleフォームで予約フォームを作りたい。
製品A~Fの6種類があり、選択後各セクションに飛んで日付をラジオボタンで選択。
その選択肢を一度予約が入ったら選択肢から削除されるようにしたい。
例:製品A→13日10時~が送信された場合、製品Aの13日10時~の選択肢を削除する。
発生している問題・分からないこと
asMultipleChoiceItemが上手く機能せず、エラーが発生してしており、
変数を確認しても条件を満たしている気がしてなりません。
当方GASを組み始めての経験が浅く、Geminiに聞きながらの構築になります。
エラーメッセージ
error
1TypeError: item.asMultipleChoiceItem(...).getResponse is not a function 2 at onFormSubmit(コード:45:55)
該当のソースコード
GAS
1function onFormSubmit(e) { 2 var formResponse = e.response; 3 var itemResponses = formResponse.getItemResponses(); 4 5 var product = itemResponses[5].getResponse(); 6 7 var properties = PropertiesService.getDocumentProperties(); 8 var selectedTimes = properties.getProperty(product); 9 selectedTimes = selectedTimes ? JSON.parse(selectedTimes) : []; 10 11 var form = FormApp.getActiveForm(); 12 var items = form.getItems(); 13 14 var sectionIndex = getProductSectionIndex(product, items); 15 16 if (sectionIndex !== undefined && sectionIndex < items.length - 1) { 17 var itemIndex = sectionIndex + 1; 18 19 if (itemIndex < items.length) { 20 var item = items[itemIndex]; 21 22 if (item && item.getType() === FormApp.ItemType.MULTIPLE_CHOICE) { 23 var meetingTime = item.asMultipleChoiceItem().getResponse()[0]; 24 selectedTimes.push(meetingTime); 25 properties.setProperty(product, JSON.stringify(selectedTimes)); 26 updateMeetingTimeChoices(item, selectedTimes); 27 } 28 } 29 } 30} 31 32function getProductSectionIndex(product, items) { 33 var productSections = { 34 "製品A": "製品A", 35 "製品B": "製品B", 36 "製品C": "製品C", 37 "製品D": "製品D", 38 "製品E": "製品E", 39 "製品F": "製品F" 40 }; 41 42 for (var i = 0; i < items.length; i++) { 43 if (items[i].getType() === FormApp.ItemType.PAGE_BREAK && items[i].getTitle() === productSections[product]) { 44 return i; 45 } 46 } 47 return undefined; 48} 49 50function updateMeetingTimeChoices(sectionItem, selectedTimes) { 51 if (sectionItem && sectionItem.getType() === FormApp.ItemType.MULTIPLE_CHOICE) { 52 var originalChoices = ["13日(木) 10時~", "13日(木) 11時~", "13日(木) 13時~", "13日(木) 14時~", "14日(金)10時~", "14日(金)11時~", "14日(金)13時~", "14日(金)14時~"]; 53 var availableChoices = originalChoices.filter(function(choice) { 54 return selectedTimes.indexOf(choice) === -1; 55 }); 56 57 if (availableChoices.length > 0) { 58 sectionItem.asMultipleChoiceItem().setChoiceValues(availableChoices); 59 } 60 } 61}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
セクションを跨いだフォームの修正が記載されたサイトを見つける事が出来ませんでした。
変数の確認をログの出力で行っており、私の目からは問題ないように見えるのですが、エラーを改善できませんでした。
補足
こちらは当該のGoogleフォームです。

回答1件
あなたの回答
tips
プレビュー