通过 google 脚本设置一个 Google 表单目标到它的响应
Setting a Google Form destination to it responses via google script
我正在尝试设置一个脚本来创建基于 sheet 的表单(有效),然后我希望它提交对特定 sheet 的回复,这样我就可以让脚本与之交互,手动将表单连接到 sheet 是不切实际的,因为每天都可以创建多个表单
当我 运行 脚本出现此错误代码时
异常:在对象 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 = "insertgenertic@email.com";
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);
}
form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);
ssId 应该是 Spreadsheet 的 id 而不是 sheet
您不能将表单回复发送到之前存在的 sheet。当您 link 将您的表单传播到目的地时 sheet,它总是会创建一个新的 sheet 来存储这些响应,无论您是否使用 Apps 脚本来设置目的地。您只能选择是现有点差sheet还是新点差。
因此,您必须在调用 Form.setDestination(type, id) 时提供点差 sheet id。由于您提供的是 sheet ID,因此您收到了一个错误。
你应该这样做:
function bug() {
// ...
const spreadsheetId = SpreadsheetApp.getActive().getId();
form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheetId);
// ...
}
相关:
我正在尝试设置一个脚本来创建基于 sheet 的表单(有效),然后我希望它提交对特定 sheet 的回复,这样我就可以让脚本与之交互,手动将表单连接到 sheet 是不切实际的,因为每天都可以创建多个表单
当我 运行 脚本出现此错误代码时
异常:在对象 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 = "insertgenertic@email.com";
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);
}
form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);
ssId 应该是 Spreadsheet 的 id 而不是 sheet
您不能将表单回复发送到之前存在的 sheet。当您 link 将您的表单传播到目的地时 sheet,它总是会创建一个新的 sheet 来存储这些响应,无论您是否使用 Apps 脚本来设置目的地。您只能选择是现有点差sheet还是新点差。
因此,您必须在调用 Form.setDestination(type, id) 时提供点差 sheet id。由于您提供的是 sheet ID,因此您收到了一个错误。
你应该这样做:
function bug() {
// ...
const spreadsheetId = SpreadsheetApp.getActive().getId();
form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheetId);
// ...
}