Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否将两个onEdit与if函数合并?_Javascript_Google Apps Script_Google Sheets_Triggers - Fatal编程技术网

Javascript 是否将两个onEdit与if函数合并?

Javascript 是否将两个onEdit与if函数合并?,javascript,google-apps-script,google-sheets,triggers,Javascript,Google Apps Script,Google Sheets,Triggers,我在互联网站上收集了谷歌表单的脚本,并在这里得到了一些帮助。否我有2个onEdit冲突。我通过为onEdit2创建脚本触发器克服了这一问题。这是可行的,但我认为这不是最好的解决方案。你能帮我把这两个分开的onEdit和if函数合为一个吗 //Dependent Dropdown list function onEdit(e){ // Function that runs when we edit a value in the table. masterSelector(master1,mas

我在互联网站上收集了谷歌表单的脚本,并在这里得到了一些帮助。否我有2个
onEdit
冲突。我通过为
onEdit2
创建脚本触发器克服了这一问题。这是可行的,但我认为这不是最好的解决方案。你能帮我把这两个分开的
onEdit
和if函数合为一个吗

//Dependent Dropdown list
function onEdit(e){ // Function that runs when we edit a value in the table.
  masterSelector(master1,master2,master3,master4);
  var activeCell = e.range; // It returns the coordinate of the cell that we just edited.
  var val = activeCell.getValue(); // Returns the value entered in the column we just edited.
  var r = activeCell.getRow(); // returns the row number of the cell we edit.
  var c = activeCell.getColumn(); // returns the column number of the cell we edit.

  var wsName = activeCell.getSheet().getName();
  if (wsName === masterWsName && c === firstLevelColumn && r > masterNumberOfHeaderRows) { // the if delimits the section sensitive to modification and action of the onEdit.
    applyFirstLevelValidation(val,r);
  } else if (wsName === masterWsName && c === secondLevelColumn && r > masterNumberOfHeaderRows){
      applySecondLevelValidation(val,r);
    }
} // end of onEdit

// addRow by checkboxes 
function onEdit2(e) {
    masterSelector(master1,master2,master3,master4);
  //IF the cell that was edited was in column 4 = D and therefore a checkbox AND if the cell edited was checked (not unchecked):
  if (e.range.columnStart === 4 && e.range.getValue() === true) {
    var sheet = SpreadsheetApp.getActiveSheet(),
        row = sheet.getActiveCell()
        .getRow(),
        //(active row, from column, numRows, numColumns)
        rangeToCopy = sheet.getRange(row, 1, 1, 30);
    sheet.insertRowAfter(row);
    rangeToCopy.copyTo(sheet.getRange(row + 1, 1));
    //Reset checked boxes in column 4
    sheet.getRange(row,4,2,1).setValue(false);
  }
}

如果需要,可以使用整个脚本。

将第一个
onEdit
函数重命名为
onEdit1
(实际上最好指定一个描述性名称),然后添加以下函数:

function onEdit(e){
  onEdit1(e);
  onEdit2(e);
}
相关的


将第一个
onEdit
函数重命名为
onEdit1
(实际上最好指定一个描述性名称),然后添加以下函数:

function onEdit(e){
  onEdit1(e);
  onEdit2(e);
}
相关的