繁体   English   中英

谷歌表格时间戳通过应用程序脚本

[英]Google sheets timestamp via apps script

首先让我说我对谷歌应用程序脚本和 JavaScript 非常陌生。 我正在编写一个脚本,该脚本将在第 13 列从下拉列表中将其状态更改为“已接受”或“进行中”时添加时间戳,然后根据选择的状态将时间戳放入第 24 列或 25 列。 它还检查目标单元格中是否已有文本。

我的问题是第一部分工作正常,选择“接受”将完全按照它应该输入的时间戳,但是当我 select“进行中”时没有任何反应。 我认为这可能是由于我的 {} 括号放置,但我自己无法弄清楚。 输入将不胜感激。

function onEdit(e) {  

  addTimestamp(e);

  
}

function addTimestamp(e){
  //variables
  var startRow = 3;
  var currentDate = new Date();
  var targetColumn = 13;
  var ws = "Call Log";
  var ss = "Copy of Project Worksheets (for testing)";
  //get modified row and column
  var row = e.range.getRow();  //value for row
  var col = e.range.getColumn(); //value for the column
  
    if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { 
// Checks the name of the sheet you are working on, in this case its Call log.
      if(e.source.getActiveSheet().getRange(row,13).getValue() =="Accepted"){
        if(e.source.getActiveSheet().getRange(row,24).getValue() =="")
          e.source.getActiveSheet().getRange(row,24).setValue(currentDate);}
        
      if (e.source.getActivesheet().getRange(row,13).getValue() =="In Progress"){
        if(e.source.getActiveSheet().getRange(row,25).getValue() =="")
          e.source.getActiveSheet().getRange(row,25).setValue(currentDate);}
  } // END IF check column, row, and worksheet name
 } // END IF function addTimestamp```

您在getActivesheet()中有拼写错误

改变:

if (e.source.getActivesheet().getRange(row,13).getValue() =="In Progress")

if (e.source.getActiveSheet().getRange(row,13).getValue() =="In Progress")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM