gpt4 book ai didi

javascript - Google 表单编辑链接不提交现有值,只提交那些在使用 google 脚本时更改的值?

转载 作者:行者123 更新时间:2023-11-29 10:26:23 26 4
gpt4 key购买 nike

我有一个链接到 google 表格的 google 表单。在提交表单时,回复会自动填写一个文档模板并生成一个 pdf 文件,并将其保存在驱动器上。我还有一个脚本,如果他们想要更改信息,该脚本会使用表单提交的编辑链接填充一列。初始提交时一切正常,但在编辑表单时,提交时仅提交已更改的信息,因此大部分信息未定义。

有什么想法吗?

我这样收集表单数据:

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 函数的一些数据。它看起来像这样:

enter image description here

将所有编辑与给定表单提交相关联的一条数据是最后一列,它是 Form Responses 4 Sheet 中第一个表单条目的行号,这是我用于此代码的表单行号来自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.
}
}

关于javascript - Google 表单编辑链接不提交现有值,只提交那些在使用 google 脚本时更改的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58291230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com