【问题标题】:script.google.com error: TypeError: Cannot read property 'values' of undefinedscript.google.com 错误:TypeError:无法读取未定义的属性“值”
【发布时间】:2021-12-07 07:31:09
【问题描述】:

我正在尝试使用表单提交来自动完成我创建的谷歌文档模板。但是我不断收到错误 TypeError: Cannot read property 'values' of undefined, 我是一个完整的新手,有人可以帮帮我吗?

function autoFillGoogleDocFromForm(e) {
  //e.values is an array of form values
  var timestamp = e.values[0];
  var EmailAddress = e.values[1];
  var CallReportWriter = e.values[2];
  var DateOfMeeting = e.values[3];
  var NameOfTheCustomerProspect  = e.values[4];
  var ContactNameFromClient = e.values[5];
  var TitleandContacts = e.values[6];
  var PresentfromSesomo = e.values[7];
  var MeetingObjectives = e.values[8];
  var MeetingResult = e.values[9];
  var Background = e.values[10];  
  var Opportunities = e.values[11];  
  var Followuprequired = e.values[12];  
  var Responsible = e.values[13];  
  var Targetdates = e.values[14];  


  
  //file is the template file, and you get it by ID
  var file = DriveApp.getFileById('12zJTxLgy_Nmxk1FScyZ3vqHzYnKQ55ckdQ8RsYy-MdA'); 
  
  //We can make a copy of the template, name it, and optionally tell it what folder to live in
  //file.makeCopy will return a Google Drive file object
  var folder = DriveApp.getFolderById('1SorfCjOGknFVt1ch39MJ7atBorLf_Sdr')
  var copy = file.makeCopy(DateOfMeeting + ',' + NameOfTheCustomer/Prospect, CallReport); 
  
  //Once we've got the new file created, we need to open it as a document by using its ID
  var doc = DocumentApp.openById(copy.getId()); 
  
  //Since everything we need to change is in the body, we need to get that
  var body = doc.getBody(); 
  
  //Then we call all of our replaceText methods
  body.replaceText('{{MeetingDate}}', DateOfMeeting); 
  body.replaceText('{{NameOfCustomer}}', NameOfTheCustomer/Prospect);  
  body.replaceText('{{ReportWriterName}}', CallReportWriter); 
  body.replaceText('{{ContactNameFromClient}}', ContactNameFromClient); 
  body.replaceText('{{TitleAndContact}}', TitleandContacts); 
  body.replaceText('{{PresentFromSesomo}}', PresentfromSesomo); 
  body.replaceText('{{MeetingObjectives}}', MeetingObjectives); 
  body.replaceText('{{MeetingResults}}', MeetingResult); 
  body.replaceText('{{Background}}', Background); 
  body.replaceText('{{Opportunities}}', Opportunities); 
  body.replaceText('{{FollowUpRequired}}', Followuprequired); 
  body.replaceText('{{Responsible}}', Responsible); 
  body.replaceText('{{TargetDate}}', Targetdates); 
  
  //Lastly we save and close the document to persist our changes
  doc.saveAndClose(); 
} 

【问题讨论】:

  • debug 提供调试细节。
  • 我希望你不要试图从脚本编辑器运行它,因为那是行不通的。

标签: templates google-apps-script google-docs google-forms


【解决方案1】:

打开表单响应所在工作表的脚本编辑器

//
function onFormSubmit(e) {
  var resp = e.source.getActiveSheet().getRange(e.range.rowStart,1, e.range.rowStart,14 ).getValues();

  var timestamp = resp[0][0];
  var EmailAddress = resp[0][1];
  var CallReportWriter = resp[0][2];
  var DateOfMeeting = resp[0][3];

// continue your code - I have not tested it


}

在脚本编辑器中,您必须安装表单提交触发器

然后,一旦表单响应落地,您的代码就会运行并做任何您想做的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 2023-02-26
    • 2017-05-05
    • 2019-04-05
    • 2020-09-03
    相关资源
    最近更新 更多