Javascript 谷歌表单编辑链接不提交现有值,只提交在使用谷歌脚本时更改的值?
我有一个谷歌表单链接到谷歌表单。在表单提交时,响应会自动填写文档模板并生成pdf,并将其保存在驱动器上。我还有一个脚本,如果他们想更改信息,可以用表单提交的编辑链接填充列。在初次提交时,一切都很完美,但在编辑表单时,提交时,仅提交已更改的信息,从而使大多数信息未定义 有什么想法吗 我收集的表单数据如下:Javascript 谷歌表单编辑链接不提交现有值,只提交在使用谷歌脚本时更改的值?,javascript,google-apps-script,google-sheets,google-drive-api,google-forms,Javascript,Google Apps Script,Google Sheets,Google Drive Api,Google Forms,我有一个谷歌表单链接到谷歌表单。在表单提交时,响应会自动填写文档模板并生成pdf,并将其保存在驱动器上。我还有一个脚本,如果他们想更改信息,可以用表单提交的编辑链接填充列。在初次提交时,一切都很完美,但在编辑表单时,提交时,仅提交已更改的信息,从而使大多数信息未定义 有什么想法吗 我收集的表单数据如下: function generateQuote(e) { //collect form responses and store in variables var QuoteID = Util
function generateQuote(e) {
//collect form responses and store in variables
var QuoteID = Utilities.formatDate(new Date(), "CDT", "yyMMddHHss");
var CustomerName = e.namedValues['Name of Power Plant'][0] !=''? e.namedValues['Name of Power Plant'][0] : ' ';
var CustomerAddress = e.namedValues['Address'][0] !=''? e.namedValues['Address'][0] : ' ';
}
获取表单编辑期间未更改的所有其他值。 我有一个日志表,其中保存了onFormSubmit函数的一些数据。看起来是这样的:
function generateQuote(e) {
//collect form responses and store in variables
var QuoteID = Utilities.formatDate(new Date(), "CDT", "yyMMddHHss");
var CustomerName = e.namedValues['Name of Power Plant'][0] !=''? e.namedValues['Name of Power Plant'][0] : ' ';
var CustomerAddress = e.namedValues['Address'][0] !=''? e.namedValues['Address'][0] : ' ';
}
将所有编辑绑定到给定表单提交的一段数据是最后一列,它是表单响应4表中第一个表单条目的行号,这是我用于此代码的表单,行号来自e.range.rowStart
这是onFormSubmit函数:
function testFormSubmission(ev) {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('LogSheet');
var tA=ev.values;//from the event object
tA=tA.concat([ev.range.rowStart]);//from the event Object
sh.appendRow(tA);//The ev.values will be replaced in a moment but the ev.range.rowStart will remain on the line allowing you to always know which entry on the Form Response Sheet is being edited
var lr=sh.getLastRow();
if(sh.getRange(lr,2).isBlank() || sh.getRange(lr,3).isBlank() || sh.getRange(lr,4).isBlank()) {//if any of these are blank then I assume that this is an edit. Unfortunately, it could also be a spurious trigger. But we haven't seen those for a while so I assumed that they are response edits.
var vA=ev.range.getSheet().getDataRange().getValues();//These are all of the values on the Form Responses 4 sheet
tA=[vA[ev.range.rowStart-1]];//Since I used getDataRange() and start from 1 to skip the header then I know that the correct array index is row number - 1 so that gets me the row contents of Form Responses 4 Sheet.
sh.getRange(lr,1,1,tA[0].length).setValues(tA);//Using set values I copied that data into the last row of the logSheet into the line which I just appended thus providing all of the responses including the edited response.
}
}
如果您收集电子邮件地址并将以前提交的内容保存在一张工作表中,您可能会返回到最新的一份并获取其余的响应。@Cooper我如何使用google脚本自动生成新的pdf,尽管有这些详细信息?您现在是否存储所有提交内容?如果是,电子表格是什么样子的。是的,我是这样做的,它是默认的标题和下面输入的数据,并在“编辑Url”的末尾添加了一列,在那里我填充了编辑链接。