Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

javascript - Google Sheet - script with onEdit is not always working

I have created Google Sheet file with script which should, when one checkbox is checked, clear some fields in other cells, set date in some cells and increase some counters in some cells. And this script is sometimes running and sometimes not. I have check logs and everything looks ok. I'm using onEdit function which checks if this checkbox was checked. The worst is that for me it's always working (both on computer and on phone), but for some people who are using it not, so I'm not able to recreate this problem to pinpoint the cause. Does anybody has any idea what is happening or how to fix it?

Code:

function onEdit(eventObj) {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var curRow = eventObj.range.getRow();
var idCell = sheet.getRange(curRow, idColumn);
if (!idCell.getValue())
{
  rangeIdColumn = sheet.getRange(3,idColumn,300,1);
  var values = rangeIdColumn.getValues();

  max = 0;
  for (var row in values) 
  {
    if (values[row][0] && values[row][0] > max)
      max = values[row][0];
  }
  idCell.setValue(max + 1);
}

const checkedColumn = 3
if (eventObj.range.getColumn() == checkedColumn && eventObj.range.getValue())
{
  var curRow = eventObj.range.getRow();
  var curRange = sheet.getRange(curRow, 1, 1, 60);
  var curValues = curRange.getValues();
  for (col = startColumn; col < endColumn; col += 3)
  {  
    //check if was requested
    if(curValues[0][col])
    {
      curRange.getCell(1, col + 1).setValue(false);    
      curRange.getCell(1, col + 2).setValue(new Date());
      var num = curValues[0][col + 2];
      if (num)
        curRange.getCell(1, col + 3).setValue(Number(num) + 1);
      else
        curRange.getCell(1, col + 3).setValue(1);
    }
  }
  curRange.getCell(1, endColumn + 3).setValue("");
  curRange.getCell(1, checkedColumn - 1).setValue(false);
  curRange.getCell(1, checkedColumn).setValue(false);

}
}
question from:https://stackoverflow.com/questions/65846710/google-sheet-script-with-onedit-is-not-always-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...