質問

I am trying to create a calendar event in Google App Script, it is similar to the "QuickAdd" format that is used in the calendar. I used the createEventFromDescription method, I checked the execution transcript and it creates the event successfully but then the script shows an error when running the script.

The error message is "Error Encountered: An unexpected error occured"

I don't know what I have done wrong, it creates the event. Below is the code:

function doGet(){

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

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

 var eventTitleLabel = app.createLabel('Event Title:');
 var eventTitle = app.createTextBox().setName('eventTitle');
 var eventButton = app.createButton('Create Events');
 var cancelButton = app.createButton('Cancel');

 left.add(eventTitleLabel)
     .add(eventTitle);  

 right.add(eventButton)
      .add(cancelButton);

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

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

 parent.add(left)
       .add(right);

 app.add(parent);

 app.close();
 return app;
}

function createEvents(e){

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

try{
  //get the entries;
  var event = e.parameter.eventTitle;


  //Get the calendar
  var cal = CalendarApp.getDefaultCalendar();
  cal.createEventFromDescription(event);

  app.add(app.createLabel('Event created Successfully'));

  //make the form panel invisible
  app.getElementById('panel').setVisible(false);
  return app;
}

//If an error occurs, show it on the panel
 catch(e){
  app.add(app.createLabel('Error occured: '+e));
  return app;
 }
}
役に立ちましたか?

解決

You are calling getElementById ('panel') but there is no widget called 'panel'... the closest is the panel called 'parent', is that the one you want to hide?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top