【问题标题】:Setting a Google Form destination to it responses via google script通过谷歌脚本将谷歌表单目标设置为响应
【发布时间】:2021-10-27 05:41:06
【问题描述】:

我正在尝试设置一个脚本,该脚本基于工作表创建表单(有效)然后我希望它提交对特定工作表的响应,以便我可以让脚本与之交互,手动连接表单因为每天都可以创建多个表单,所以添加到工作表中并不实用

当我运行脚本时出现此错误代码

异常:在对象 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);

}

【问题讨论】:

    标签: javascript google-apps-script google-sheets google-forms


    【解决方案1】:

    您不能将表单回复发送到以前存在的工作表。当您将表单链接到目标电子表格时,无论您是否使用 Apps 脚本设置目标,它都会始终创建一个新工作表来存储这些响应。您只能选择是现有电子表格还是新电子表格。

    因此,您在调用Form.setDestination(type, id) 时必须提供电子表格ID。由于您提供的是工作表 ID,因此您会收到错误消息。

    你应该这样做:

    function bug() {
      // ...
      const spreadsheetId = SpreadsheetApp.getActive().getId();
      form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheetId);
      // ...
    }
    

    相关:

    【讨论】:

    • 谢谢 Lambichus 和 Cooper,我希望这是可能的,但我只会发送一个触发脚本来移动信息,然后在创建工作表后,感谢您的帮助
    【解决方案2】:

    form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);

    ssId 应该是电子表格的 id 而不是工作表

    example

    spreadsheet id

    getSheetId

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多