我正在嘗試設定一個基于作業表創建表單的腳本(有效)然后我希望它提交對特定作業表的回應,以便我可以讓腳本與其互動,手動將表單連接到作業表不實用,因為每天都可以創建多個表單
當我運行腳本時出現此錯誤代碼
例外:獲取物件 FormApp.Form 上的方法或屬性 setDestination 時出現意外錯誤。
以下是我的代碼,任何幫助都將得到回報
function bug() {
var sheet = SpreadsheetApp.getActive().getSheetByName('TC');
var value = sheet.getRange("A3").getValue();
var em = sheet.getRange("B3").getValue();
var cos = sheet.getRange("E3").getValue();
var name = sheet.getRange("D3").getValue();
var sup = sheet.getRange("C3").getValue();
var form = FormApp.create(value);
var item = form.addMultipleChoiceItem();
item.setHelpText("Name: " name
"\n\nEmail: " em
"\n\nQuote No: " value
"\n\nProject: " sup
"\n\nTotal Cost: " cos
"\n\nBy selecting approve you agree to the cost and timeframe specified by the quote and that the details above are correct")
.setChoices([item.createChoice('Approve'), item.createChoice('Deny')]);
var item = form.addCheckboxItem();
item.setTitle('What extras would you like to add on?');
item.setChoices([
item.createChoice('Damp-Course'),
item.createChoice('Wrap'),
item.createChoice('Taco')
]);
Logger.log('Published URL: ' form.getPublishedUrl());
Logger.log('Editor URL: ' form.getEditUrl());
Logger.log('ID: ' form.getId());
var ssId = sheet.getSheetId();
form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);
var SendTo = "[email protected]";
var link = form.getPublishedUrl();
var message = "Please follow the link to accept you Quotation " form.getPublishedUrl();
//set subject line
var Subject = 'Quote' value 'Confirmation';
const recipient = em;
const subject = "Confirmation of order"
const url = link
GmailApp.sendEmail(recipient, subject, message);
}
uj5u.com熱心網友回復:
您不能將表單回復發送到以前存在的作業表。當您將表單鏈接到目標電子表格時,無論您是否使用 Apps 腳本來設定目標,它都會創建一個新作業表來存盤這些回應。您只能選擇它是現有電子表格還是新電子表格。
因此,您必須在呼叫Form.setDestination(type, id)時提供電子表格 ID 。由于您提供的是作業表 ID,因此您會收到錯誤訊息。
你應該做這樣的事情:
function bug() {
// ...
const spreadsheetId = SpreadsheetApp.getActive().getId();
form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheetId);
// ...
}
有關的:
- 將 Google 表單回復鏈接到現有的 Google 電子表格選項卡
- 選擇保存表單回復的位置
uj5u.com熱心網友回復:
form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);
ssId 應該是電子表格的 ID,而不是作業表
例子
電子表格編號
獲取作業表ID
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339391.html
標籤:javascript 谷歌应用程序脚本 谷歌表格 谷歌表单
