当受访者发送响应时我捕获此事件
https://developers.google.com/apps-script/guides/triggers/events#form-submit_4
在此函数内,我想将一些信息添加到目标电子表格中的相应行(Google 自动创建此行)
为了做到这一点,首先我需要找到这一行
目前我能找到的最好方法是使用 sheet.getLastRow()
https://developers.google.com/apps-script/reference/spreadsheet/sheet#getlastrow
但是这个方法存在并发问题:Serge insas在这里说的:https://stackoverflow.com/a/17751544/2667212
There are a few risks to use that simple "strategy" as there might be concurrency issues when 2 or more people send a form simultaneously
有没有正确的方法来实现这一目标?
最佳答案
解决方案:
最简单的方法是禁用 Google 提供的自动电子表格链接并使用自定义链接。
片段:
function formSubmitInForm(e){
const formResponse = e.response;
const id = formResponse.getId();
const timestamp = formResponse.getTimestamp();
const sheet = SpreadsheetApp.openById(/*SPREADSHEET ID*/)
.getSheetByName(/*FORM RESPONSE SHEET*/);
const responses = formResponse.getItemResponses().map(function(itemRes){
return itemRes.getResponse();
})
sheet.appendRow([id,timestamp].concat(responses))
}
引用:
关于google-apps-script - Google Apps 脚本 - 如何在 onFormSubmit (Google Forms 事件)中获取目标电子表格中的相应记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57736961/