添加新行时自动插入日期戳

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

我正在通过Zapier从我们网站上的表单提交中收集数据。每次提交表单时,Zapier都会自动将新行添加到Google表格中,并将数据填充到B:L列中。在A列中,我希望每行都有一个日期戳(YYYY-MM-DD)。

目前,我有这个脚本,可以在网上找到。如果我手动编辑工作表,此方法有效。但是,当Zapier将数据推送到工作表(https://docs.google.com/spreadsheets/d/1HnxQmAQlLVLsLG_RKJwkmzzObwlwe8hHlAHd65zLjSc/edit?usp=sharing)时,脚本不会触发。

function onEdit(event)
{ 
  var timezone = "GMT+2";
  var timestamp_format = "YYYY-mm-dd"; // Timestamp Format. 
  var updateColName = "Country";
  var timeStampColName = "Date";
  var sheet = event.source.getSheetByName('Sheet1');


  var actRng = event.source.getActiveRange();
  var editColumn = actRng.getColumn();
  var index = actRng.getRowIndex();
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
  var dateCol = headers[0].indexOf(timeStampColName);
  var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
  if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself!
    var cell = sheet.getRange(index, dateCol + 1);
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
    cell.setValue(date);
  }
}

我应如何编辑此脚本以使其与自动行更新一起使用?还是有人可以让我尝试其他脚本?

date google-apps-script google-sheets timestamp zapier
1个回答
0
投票

onEdit功能does not trigger when used with the API。因此,简短的答案将是否。

但是,您可以尝试修改您的Zappier挂钩以添加时间戳。

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.