为什么我的Google日历脚本不会运行?

时间:2014-03-09 16:44:21

标签: javascript google-apps-script google-api google-calendar-api

我正在使用Google Script创建一个可以创建活动的表单,您可以从我使用过两个面板的代码中看到。我想在“父”面板上创建多个事件表单,我正在尝试使用“子”来保存有关该事件的信息。我想在每个子面板上运行createEvent(),但是当我运行它时脚本将无法运行并显示此错误消息:

  

“发生错误:InternalError:无法找到方法createEvent((class),(class),(class),object)。”

function doGet(){

 var app = UiApp.createApplication().setTitle('Create Events');

 //Create a penel which holds all the form elelemnts
 var parent = app.createHorizontalPanel().setId('parent');
 var panelOne = app.createVerticalPanel().setBorderWidth(2);

 var eventTitleLabel = app.createLabel('Event Title:');
 var eventTitle = app.createTextBox();
 var eventStartDateLabel = app.createLabel('Event Start Date:');
 var evenStartDate = app.createDateBox();
 var eventEndDateLabel = app.createLabel('Event End Date:');
 var evenEndDate = app.createDateBox();
 var eventDeatilLabel = app.createLabel('Event Details:');
 var eventDetail = app.createTextArea().setSize('150', '100');
 var eventButton = app.createButton('Create Events');
 var cancelButton = app.createButton('Cancel');

 panelOne.add(eventTitleLabel)
         .add(eventTitle)
         .add(eventStartDateLabel)
         .add(evenStartDate)
         .add(eventEndDateLabel)
         .add(evenEndDate)
         .add(eventDeatilLabel)
         .add(eventDetail)
         .add(eventButton)
         .add(cancelButton);

  var eventHandler = app.createServerClickHandler('createEvents');
  eventHandler.addCallbackElement(parent);

  //Add this handler to the button
  eventButton.addClickHandler(eventHandler);

  parent.add(panelOne);

  app.add(parent);

  app.close();
  return app; 
  }


  function createEvents(e){

  //Get the active application
  var app = UiApp.getActiveApplication();

  try{
      var eventTitle = e.parameter.eventTitle;
      var eventStartDate = e.parameter.eventStartDate;
      var eventEndDate = e.parameter.eventEndDate;
      var eventDetails = e.parameter.eventDetail;

      var cal = CalendarApp.getDefaultCalendar();
   cal.createEvent(eventTitle, eventStartDate,eventEndDate,{description:eventDetails});

app.add(app.createLabel('Event created Successfully'));
app.getElementById('panel').setVisible(false);
return app;
}

catch(e){
app.add(app.createLabel('Error occured: '+e));
return app;
 }
}

2 个答案:

答案 0 :(得分:0)

所有输入窗口小部件都需要.setName()才能将其值传递给服务器功能。 https://developers.google.com/apps-script/guides/ui-service#ServerHandlers

另请考虑使用Logger.log()进行调试。

答案 1 :(得分:0)

您只是忘了在您的示例中为要从中获取数据的小部件设置名称:

 var eventTitleLabel = app.createLabel('Event Title:');
 var eventTitle = app.createTextBox().setName('eventTitle');
 var eventStartDateLabel = app.createLabel('Event Start Date:');
 var evenStartDate = app.createDateBox().setName('evenStartDate');
 var eventEndDateLabel = app.createLabel('Event End Date:');
 var evenEndDate = app.createDateBox().setName('evenEndDate');
 var eventDeatilLabel = app.createLabel('Event Details:');
 var eventDetail = app.createTextArea().setSize('150', '100').setName('eventDetail');