Google表单编辑链接不提交现有值,仅提交使用Google脚本时更改的值?

问题描述 投票:3回答:1

我有一个链接到Google工作表的Google表单。在提交表单时,响应会自动填写doc模板并生成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] : ' ';
}
javascript google-apps-script google-sheets google-drive-api google-form
1个回答
2
投票

获取在表单编辑期间未更改的所有其他值。

我有一个日志表,其中保存了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.
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.