Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.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 doPost提交Web表单时遇到“意外错误”_Javascript_Google Apps Script - Fatal编程技术网

Javascript doPost提交Web表单时遇到“意外错误”

Javascript doPost提交Web表单时遇到“意外错误”,javascript,google-apps-script,Javascript,Google Apps Script,提交后,我被困在这个web表单上。下面的代码在我不久前在Serge和其他一些人的帮助下创建的一个web表单中工作。我正在尝试重新使用代码来生成PTO请求web表单。现在,当提交它时,抛出了一个意外的错误。我遇到了一个错误,我在尝试查找问题时迷失了方向。我在想,这可能是我如何将面板添加到一起,以及它们之间的关系?这是一项正在进行的工作,因此我知道将添加ClickHandler,以便在提交等之后提供响应。目前,我希望确保它将表单中的条目传递到电子表格中。谢谢你的帮助 //Setting the sp

提交后,我被困在这个web表单上。下面的代码在我不久前在Serge和其他一些人的帮助下创建的一个web表单中工作。我正在尝试重新使用代码来生成PTO请求web表单。现在,当提交它时,抛出了一个意外的错误。我遇到了一个错误,我在尝试查找问题时迷失了方向。我在想,这可能是我如何将面板添加到一起,以及它们之间的关系?这是一项正在进行的工作,因此我知道将添加ClickHandler,以便在提交等之后提供响应。目前,我希望确保它将表单中的条目传递到电子表格中。谢谢你的帮助

//Setting the spreadshet ID and style of the form
  var submissionSSkey = 'PUT YOUR KEY HERE'
  var PanelStyle = {'background':'#c0d6e4','padding':'40px','borderStyle':'ridge','borderWidth':'15PX','borderColor':'#31698a'}

// Script-as-app template.
function doGet(e) {
  //Creating the Appplication
  var app = UiApp.createApplication();


  //Creating panels to house the web form, instructional text, data pickers and setting style
  var vertPanel = app.createVerticalPanel().setTitle('XYX Company PTO Request Form').setStyleAttributes(PanelStyle).setPixelSize(350,250);
  var mainPanel = app.createFormPanel().setPixelSize(350,150);
  var grid = app.createGrid(4,4).setId('ptogrid');
  var ptoStart = app.createDateBox().setWidth('200').setName('ptoStartDate');
  var ptoEnd = app.createDateBox().setWidth('200').setName('ptoEndDate');
  var submitButton = app.createSubmitButton('<B>Submit</B>');

  //Assigning widgets to the grid for positioning
  grid.setText(1, 0, 'PTO Start Date')
  .setWidget(1, 1, ptoStart)
  .setText(2, 0, "PTO End Date")
  .setWidget(2, 1, ptoEnd)
  .setText(3, 0, '')
  .setWidget(3, 1, submitButton)

  //Instructions for completion of the PTO form by users.
  vertPanel.add(app.createHTML("<b>PTO Request Form</b>"));
  vertPanel.add(mainPanel);
  vertPanel.add(app.createHTML("<br><b>Instructions:</b></br>" +
                          "<p>Select the starting date and the ending date for your PTO request. "+
                          "If you are taking a single day of PTO enter the starting and ending date as the same date. "+
                           "Click Submit once you've enter the dates.  A request will be sent to your manager for reivew / approval.</p>"));

  //Grabbing active users session information in order to look up user group assignment and manager
  var employee = Session.getActiveUser().getEmail();
  //Uses the UserManager class to get info by passing in the getActive user from base class
  var userFirst = UserManager.getUser(Session.getActiveUser()).getGivenName();
  var userLast = UserManager.getUser(Session.getActiveUser()).getFamilyName();
  var wholeName = userFirst +" "+ userLast;

  mainPanel.add(grid);
  app.add(vertPanel);
  return app;
}

function doPost(e) {
  var app = UiApp.getActiveApplication();
  var ptoStart = e.parameter.ptoStartDate;
  var ptoEnd = e.parameter.ptoEndDate;
  //var wholeName = e.parameter;
  var timeStamp = new Date();


  //Access spreadsheet store values
  var sheet = SpreadsheetApp.openById(submissionSSkey).getSheetByName('PTO Requests');
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1, 1, 1, 11).setValues([[timeStamp,ptoStart,ptoEnd]]);

  app.close();
  return app;
}

我很确定错误来自电子表格ID、工作表名称或范围定义,请仔细检查这些参数,看看是否解决了问题

我用错误的值检查了我的帐户,它生成了与您相同的问题,它使用正确的值按预期工作

编辑:你的评论似乎证实了。。。我回答的时候没看到


注意:通过查看脚本编辑器UI中的执行记录,可以很容易地找到错误,它甚至会提供发生错误的代码行。

Ok。。sheet.getRangelastRow+1,1,1,11设置错误,需要为sheet.getRangelastRow+1,1,1,3执行记录非常有用。我忘了这件事,因为我上下班都在玩弄汽油。谢谢你的提醒。。