有没有一种方法可以自动按Google App脚本msgBox上的“确定”按钮?

时间:2020-02-20 17:47:29

标签: javascript google-apps-script

我有一个脚本,可引导用户扫描条形码,然后在工作表中找到条形码并在其旁边标记日期。我使用的扫描仪输入条形码的值,然后输入回车符,这样,如果我要扫描多个条形码,则输入将如下所示:

123456
123456
123456

无需我按任何按钮。我希望能够仅扫描多个项目而不必每次都按“确定”。但是Google Apps工作表不接受Enter键,可以这样做吗?

以下是我的代码示例:

    var barCodeId = Browser.inputBox('Scan Barcode', ui.ButtonSet.OK_CANCEL);
    if (barCodeId != 'cancel'){
      try{     
        sheet.createTextFinder(barCodeId).findNext().offset(0, 15).activate().setValue(date);
        var location = '892 ' + Browser.inputBox('Enter Location');
        //used to check if the item is in the same place and colors the tile if not
        colorLocation(location)
      }
      //creates a sheet and lists items not on inventory
      catch(error){
        var nonSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Not on Inventory");
        if (nonSheet == null){
          nonSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
          nonSheet.setName("Not on Inventory"); 
          createTitle(nonSheet)
        }
          SpreadsheetApp.setActiveSheet(nonSheet)
          var location = Browser.inputBox('Enter Location');
          fillInformation(barCodeId, location, date, nonSheet)
        }
    } else{
        break;
    }

1 个答案:

答案 0 :(得分:1)

您不能使用Browser.inputBox()来做到这一点。

实现此功能的最佳选择是使用自定义的HTML界面,该界面通过Ui在对话框窗口或侧边栏中显示。这将需要对基础工作流程进行一些更改,但您将具有更大的灵活性,因为您可以在表单上运行客户端javascript并在收到扫描程序的输入时执行操作。