Исходя из того, что я понял о вашей проблеме, я полагаю, что вы в основном пытаетесь поместить данные последнего элемента листа 1 в соответствующий элемент рабочего кода на листе 2. Если это не то, что вы хотели, или я неправильно понял Ваш вопрос, пожалуйста, дайте мне знать, и я обновлю этот ответ соответственно.
Однако, если я прав, это решение вашей проблемы (подробности объяснены в комментариях к этому коду):
Решение
function makeItWork(){
var wb = SpreadsheetApp.getActiveSpreadsheet();
var ss2 = wb.getSheetByName('timedata');
var ss1 = wb.getSheets()[0];
var lr = ss1.getLastRow();
var lc = ss1.getLastColumn();
// Get the desired values of the last added item including its workcode
var timestamp = ss1.getRange(lr,1).getValue();
var status = ss1.getRange(lr,4).getValue();
var workcode = ss1.getRange(lr, 3).getValue();
// Get the column values of workcode to then see which one matches with the last added item
var columnValues = ss2.getRange('A:A').getValues();
// Get values returns an Array with the elements nested in their own arrays,
// we need to flat them to be able to do the array search later
var searchValues = columnValues.flat();
// Returns the row number of the adecuate workcode if it can match it to the one of the last element
var searchResult = searchValues.indexOf(String(workcode));
if(searchResult != -1){
// If it found a match, add the data of the last element of sheet 1 in the right cells acording to the workcode match
ss2.getRange(searchResult, 4).setValue(timestamp);
ss2.getRange(searchResult, 5).setValue(status);
}
}
Надеюсь, это помогло вам, пожалуйста, дайте мне знать, если вам нужно что-то еще или вы чего-то не поняли.