Получение всех других значений, которые не были изменены во время редактирования формы.
У меня есть журнал, где я храню некоторые данные для функции onFormSubmit. Это выглядит так:
Один фрагмент данных, который связывает все изменения с отправкой формы, - это последний столбец, который является строкойномер первой записи формы в форме ответов 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.
}
}