简体   繁体   English

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

[英]Google sheets timestamp via apps script

Let me start by saying that I am very new to google apps script and JavaScript.首先让我说我对谷歌应用程序脚本和 JavaScript 非常陌生。 I am writing a script that will timestamp when column 13 gets its status changed to "Accepted" or "In Progress" from a dropdown list, and then put the timestamp into col 24 or 25, depending on which status was selected.我正在编写一个脚本,该脚本将在第 13 列从下拉列表中将其状态更改为“已接受”或“进行中”时添加时间戳,然后根据选择的状态将时间戳放入第 24 列或 25 列。 It also checks to see if there is already text in the target cell.它还检查目标单元格中是否已有文本。

My problem is that the first part works fine, selecting "Accepted" will enter the timestamp exactly as it should, but nothing happens when I select "In Progress".我的问题是第一部分工作正常,选择“接受”将完全按照它应该输入的时间戳,但是当我 select“进行中”时没有任何反应。 I think that this is probably due to my {} bracket placement but I was unable to puzzle it out myself.我认为这可能是由于我的 {} 括号放置,但我自己无法弄清楚。 Input would be greatly appreciated.输入将不胜感激。

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```

You have a typo error in getActivesheet()您在getActivesheet()中有拼写错误

Change:改变:

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

to

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

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

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