无法在函数内调用函数

时间:2020-04-20 23:16:55

标签: javascript google-apps-script google-sheets google-forms

我想运行clearAll函数来删除表单中的所有内容(可行)。 最后,我想调用dbMaker函数以重新填充表单。 (这不起作用。该功能拒绝启动)

如果我直接运行dbMaker函数,它将按预期工作。

请帮助我。 clearAll函数完成后如何运行dbMaker函数?

我进行了这项工作,由于某种原因,它停止了。我想不通。

var ssID = "something";
var formID = "something"
//SpreadsheetApp.openById(ssID).getSheetByName("db_type");
  var ss = SpreadsheetApp.openById(ssID);
  var form = FormApp.openById((formID));




function clearAll(form){
  var form = FormApp.openById((formID));
  var items=form.getItems();
  var d=0;//deleted items counter
  for (var i=0; i<items.length; i++) {
    form.deleteItem(i-d++);
      dbMaker() ;
  }

}




function dbMaker() {

  var sheets = ss.getSheets().filter(function(sheet) {return sheet.getName().match(/db_info/gi);});

  var dbSelect = form.addListItem().setTitle('DB Type').setRequired(true);



  var dbChoices = [];
  for(var i = 0; i < sheets.length; i++) {
    var dbName = sheets[i].getName();
    var dbSection = form.addPageBreakItem().setTitle(dbName).setGoToPage(FormApp.PageNavigationType.SUBMIT);

    var nativetech = getnativetech(sheets[i]);
    var nativetech_Select = form.addListItem().setTitle('Native Technology' + ' Choice').setHelpText('Select the correct DB type').setRequired(true);
    var nativetech_Choices = [];
    for(var j = 0; j < nativetech.length; j++) {
      nativetech_Choices.push(nativetech_Select.createChoice(nativetech[j]));
      Logger.log('nativetech choices', nativetech[j]);
    }


    var integratedtech = getintegratedtech(sheets[i]);
    var integratedtech_Select = form.addListItem().setTitle('Intregrated with company' + ' Choice').setHelpText('Select the correct option').setRequired(true);
    var integratedtech_Choices = [];
    for(var k = 0; k < integratedtech.length; k++) {
      integratedtech_Choices.push(integratedtech_Select.createChoice(integratedtech[k]));
      Logger.log('integratedtech choices', integratedtech[k]);
    }




    nativetech_Select.setChoices(nativetech_Choices).setRequired(true);
    integratedtech_Select.setChoices(integratedtech_Choices).setRequired(true)

    dbChoices.push(dbSelect.createChoice(dbName, dbSection));

  }
  dbSelect.setChoices(dbChoices).setRequired(true);
}

1 个答案:

答案 0 :(得分:1)

函数调用工作正常,问题可能出在dbMaker()内部。这是我所做的:

function clearAll(){
  for (var i=0; i<10;i++) {
      dbMaker(i) ;
  }
}
function dbMaker(o) {
  Logger.log(o);
}

日志:

[20-04-20 17:41:20:166 MDT] 0.0
[20-04-20 17:41:20:169 MDT] 1.0
[20-04-20 17:41:20:172 MDT] 2.0
[20-04-20 17:41:20:174 MDT] 3.0
[20-04-20 17:41:20:176 MDT] 4.0
[20-04-20 17:41:20:178 MDT] 5.0
[20-04-20 17:41:20:180 MDT] 6.0
[20-04-20 17:41:20:183 MDT] 7.0
[20-04-20 17:41:20:185 MDT] 8.0
[20-04-20 17:41:20:187 MDT] 9.0

尝试单步执行dbMaker并确保一切正常。