Skip to main content

App Script Form to add a Calender Event

Google App Script allows you to automate work flows and create Add-ons with Google Sheets, Docs and Forms. It is also possible to integrate external Google Apps.

One example is to create a Google Calender Entry or Event with an App Script. The following code snipped gives you the idea how it works:

The function doget() is responsible to define the form to enter data needed to create the event. It defines the clickhandler of the submit button.

 function doGet() {  
  var app = UiApp.createApplication();  
  var form = app.createFormPanel();  
  var grid = app.createGrid(5, 3).setId('gridForm');  
  var eventTitle= app.createTextBox().setName("eventTitle").setTitle("Event Title");  
  var descr= app.createTextBox().setName("descr").setTitle("Description");  
  var lbFromDate = app.createDateBox().setName("lbFromDate").setFormat(UiApp.DateTimeFormat.DATE_TIME_SHORT).setTitle("From");  
  var lbToDate = app.createDateBox().setName("lbToDate").setFormat(UiApp.DateTimeFormat.DATE_TIME_SHORT).setTitle("To");  
  var btnSubmit = app.createButton("Create");  
  var titleRequired= app.createLabel("*").setId('titleRequired');  
  var lblFromDateRequired = app.createLabel("*").setId('lblFromDateRequired');  
  var lblToDateRequired = app.createLabel("*").setId('lblToDateRequired');  
  grid.setWidget(0, 0, app.createLabel("Titel"));  
  grid.setWidget(1, 0, app.createLabel("Description"));  
  grid.setWidget(2, 0, app.createLabel("Von"));  
  grid.setWidget(3, 0, app.createLabel("Bis"));  
  grid.setWidget(0, 1, eventTitle);  
  grid.setWidget(1, 1, descr);  
  grid.setWidget(2, 1, lbFromDate);  
  grid.setWidget(3, 1, lbToDate);  
  grid.setWidget(4, 1, btnSubmit);  
  grid.setWidget(0, 2, titleRequired);  
  grid.setWidget(2, 2, lblFromDateRequired);  
  grid.setWidget(3, 2, lblToDateRequired);  
  form.add(grid);  
  app.add(form);  
  //Controles and click handler  
  var submitHandler = app.createServerClickHandler('validateAndCreate');  
  submitHandler.addCallbackElement(eventTitle)  
   .addCallbackElement(descr)  
   .addCallbackElement(lbFromDate)  
   .addCallbackElement(lbToDate);  
  btnSubmit.addClickHandler(submitHandler);  
   return app;  
  }  

By pressing the submit button the function validateAndCreate will be executed. This function implements a simple check of the input data an creates the Google Calender Event within the given Calendar (defined by the Calendar ID).

  function validateAndCreate(eventInfo) {  
   var app = UiApp.getActiveApplication();  
   var flag = 0;  
   var currentTimestamp = new Date();  
   app.getElementById('eventTitle').setText("*");  
   app.getElementById('lblFromDateRequired').setText("*");  
   app.getElementById('lblToDateRequired').setText("*");  
   if (eventInfo.parameter.eventTitle== ''){app.getElementById('titleRequired').setText("* Title Required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbToDate < eventInfo.parameter.lbFromDate){app.getElementById('lblToDateRequired').setText("* To Date must be later than From Date").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbFromDate == ''){app.getElementById('lblFromDateRequired').setText("* From Date required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbToDate == ''){app.getElementById('lblToDateRequired').setText("* To date required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (flag == 0){  
    var calendarId = "PUT_IN_HERE_YOUR_CALENDERID";  
    var startDt = eventInfo.parameter.lbFromDate;  
    var endDt = eventInfo.parameter.lbToDate;  
    var desc = eventInfo.parameter.desc + " created: " + currentTimestamp;  
    var title = eventInfo.parameter.eventTitle;  
    //Run the Crete event Function  
    createEvent(calendarId,title,startDt,endDt,desc);  
    app.getElementById('gridForm').setVisible(false);  
    app.add(app.createLabel("Event Created.");  
   }  
   return app;  
  }  
 function createEvent(calendarId,title,startDt,endDt,desc) {  
  var cal = CalendarApp.getCalendarById(calendarId);  
  var start = new Date(startDt);  
  var end = new Date(endDt);  
 //Manually set the Location, this can be modified to be dynamic by modifying the code if need be  
  var loc = 'YOUR LOCATION';  
 //Set the Options, in this case we are only using Description and Location, as we do not need Guests or sendInvites  
  var event = cal.createEvent(title, start, end, {  
    description : desc,  
    location : loc  
  });  
 }  

Then you can embed the App Script within your Google Sites page to visualize the form.

Comments

Popular posts from this blog

Tesla Model 3 - Dashboard Concept

Will 2017 be the year of Tesla Model 3? At last years Telsa Model 3 introduction event Elon Musk stated that first Model 3 will be shipped to customers by the end of 2017. Latest news show that currently production lines are set up and first Model 3 shall be produced by July 2017 and delivered mainly to employees as beta tester. For this reason it is very likely that we will see some Model 3 on Californias roads by mid of this year. Some expert expect the total production of cars for 2017 to 30000 up tp 50000 cars, where high production rates will be reached not before 2018.

The design of the Model 3 is well known since the introduction event back in March 2016, and it is expected that the outside will not change much. But there are some roumors that there will be quite some changes on the interior of the car especially the dashbord.

Recently I came across a new dashboard study. Have a look here.


Tesla Model 3 Future Windshield HUD User Interface Introduction

ArcGIS 10.1 Beta Launch and Deprecation Plan

ArcGIS 10.1 Beta 1 is now available for download to all those that have registered and been accepted into the program. Downloads have been made available from the Customer Care Portal and information and how to access this can be found on the ArcGIS Beta Community Site. This site is the portal for all information related to the beta.

One big drawback of ArcGIS 10.1:
There is no change in Desktop at 10.1 in regards to 64-bit support. ArcMap is a 32-bit application, but ESRI do support it running on 64-bit Windows. Currently ESRI is workung on a research project for native 64-bit ArcGIS application but it is not going to make 10.1.
ArcGIS 10.1 Deprecation Plan:
ARCGIS DESKTOP 10.1 ArcGIS 10.1 will no longer support the Solaris versions of ArcReader and ArcGIS Engine.ArcGIS 10.1 will be the last release supporting ArcReader for Linux.  SUSE Linux Enterprise Server 11 and Red Hat Enterprise Linux Server 5 will be supported.  However, SUSE Linux Enterprise Server 10 and Red Hat Enterprise Lin…

Precize 3-D model of Mount Everest

The highest mountain on earth is now available as 3D terrain model free for download. The resolution of the model is 50 by 50 cm. Not everyone can climb the Mount Everest (even though several hundred cimbs are registered each year, and still claim their victims) from their living room.


Video: Mount Everest in 3D - Herstellervideo (1:34)

Scientists of the DLR (Deutsches Institut für Luft- und Raumfahrt) together with 3D Realitymaps and Digitalglobe have calculated a realistic three-dimensional model based on satellite imagery. The software for calculating the model was originally used for making 3D models of Mars. According to scientists currently it is not possible to create a more precise model based on civil satellites. The 8848 meters high mountain was recorded by various satellites and different angles. These data builds the foundation of the terrain model and 3D textures. To use the model on your personal computer you have to install a special viewer which can be downloaded via htt…