I’m trying to create simple script that subscribes a user to a company calendar. It will be embedded in a google site. So far I have:
function doGet(e) {
var app = UiApp.createApplication();
var mainPanel = app.createVerticalPanel();
var mainButton = app.createButton("Push Me");
var clickHandler = app.createServerHandler("addCalendar");
mainButton.addClickHandler(clickHandler);
mainPanel.add(mainButton);
app.add(mainPanel);
return app;
}
function addCalendar(e) {
var app = UiApp.getActiveApplication();
var CAL_ID = (calendar's ID);
CalendarApp.subscribeToCalendar(CAL_ID);
var successLabel = app.createLabel("You have successfully added the Calendar.");
app.add(successLabel);
return app;
}
addCalendar() is being called as the successLabel is displayed, but it seems to be skipping over subscribing to the calendar. I was able to subscribe to the calendar before I added the GUI, so the problem must be related to that.
Thanks for any help!
EDIT – In the google documentation at https://developers.google.com/apps-script/guide_user_interfaces, there is a table that says UIs displayed as standalone servlets are run as the author whereas UIs displayed in spreadsheets are run as the user running the script. Could this be the root of the problem?
I think your Edit answers your question… but if your client has a ‘business’ or ‘education’ account you could read this doc to help you finding a solution.