Create Online Meeting Room Booking System Using Google Forms & Google Calendar

Create Online Meeting Room Booking System Using Google Forms & Google Calendar
Check the Demo here https://www.bifpcl.com/bookres.aspx

This simple feature is not available and you have to buy it from app developers. Here it is available free for you.

First create Google form like this for Meeting Room Booking:


This form will simply add events on a google Calendar like this:


Now go to response excel sheet. Where your response will be saved. Go to Tools and Open Script editor


In script editor we will write the code for adding event in google Calendar on submission of form.
On execute you will not be able to run this code. As this code will be run using triggers on submission of Google forms. You can only check the log by pressing Ctrl + Enter

Write the following Code:
The key steps of this script are to first get an incoming form response and then second, turn the form response into a calendar event. We will write two functions to accomplish these two steps and wrap them in an onFormSubmit function, which will be triggered to run on form submit.

I am just looping through all the form responses and storing relevant values in to some variable. Which i have used to create a calendar event at bottom of my code.

Copy the code from here:

//var moment = Moment.load();
function onFormSubmit(e) {
  var eventDate = ""; //new Date();//e.parameter.eventDate;
    var eventTitle = "Test cal"; //e.parameter.eventTitle;
    var eventDetails = "Lets see"; //e.parameter.eventDetail;
      var eventEnd = "Lets see";
  
    var i = 0;
  var values = e.namedValues;
  for (Key in values) {
    var label = Key;
    var data = values[Key];
    Logger.log(label + ": " + data);
    //if (i==0) {
    if (label.indexOf('Name') > -1){
      eventDetails = data; //booked by
    }
    // if (i==1) {
     if (label.indexOf('Date') > -1){
     eventDate = data;  //date of meeting
  //  eventDate = moment(data).toISOString();
 // Logger.log(eventDate);
    }
    // if (i==2) {
     if (label.indexOf('Room') > -1){
      eventTitle = data;
    }
   //  if (i==4) {
     if (label.indexOf('Duration') > -1){
     eventEnd = data;  //duration of meeting
    }
    i = i + 1;
    
  };
  Logger.log("Going for calander");
   
    
    //Get the calendar
   // var cal = CalendarApp.getCalendarsByName('Calendar-Name')[0];//Change the calendar name
  
  var cal = CalendarApp.getCalendarById('bifpcl.com_livqpmss5e51gh6qpjcdmsbt9o@group.calendar.google.com');
Logger.log('The calendar is named "%s".', cal.getName());
 var eventStartTime =  new Date(eventDate);
   Logger.log(eventStartTime);
    //End time is calculated by adding an hour in the event start time 
  //var eventEndTime = new Date(eventStartTime.getDate + " " + eventEnd);
 var MILLIS_PER_DAY = 1000 * 60 * 60 * (parseInt(eventEnd,10));
  
  var eventEndTime = new Date(  eventStartTime.getTime() + MILLIS_PER_DAY);
   Logger.log(eventEndTime);
    //Create the events
   // cal.createEvent(eventTitle, eventStartTime,eventEndTime ,{description:eventDetails});
  if (eventStartTime > eventEndTime)
  {
    eeventEndTime = new Date(  eventStartTime.getTime() + (1000 * 60 * 60 * 2));
  }
  // Creates an event for the moon landing and logs the ID.
  var event = cal.createEvent(eventTitle + " By:" + eventDetails,
    eventStartTime,
    eventEndTime,
    {description: "MSTPP"});
Logger.log('Event ID: ' + event.getId());
  
}


/**
 * Creates a single Date object from separate date and time cells.
 *
 * @param {Date} date A Date object from which to extract the date.
 * @param {Date} time A Date object from which to extract the time.
 * @return {Date} A Date object representing the combined date and time.
 */
function joinDateAndTime_(date, time) {
  date = new Date(date);
  date.setHours(time.getHours());
  date.setMinutes(time.getMinutes());
  return date;
}




Now go to Triggers . Click Edit > Current Projects Triggers. 


It should have onFormSubmit function selected, Event source From spreadsheet, Event type On Form Submit.
Choose the onFormSubmit function in the first drop down. Next choose "From spreadsheet" from the next drop down. Choose "On form submit" from the third drop down and then click "Save." Now whenever a new form submission comes in, the onFormSubmit function we've written will run. 

that's it. Now your code will run when you submit the Google Forms. You can check execution detail error etc in trigger section also.

Now it's time to make your Calendar ready. For that create a new calendar in Google Calendar.

Copy this iframe embed code to use in your website. Or you can use url of calendar for sharing the booking details with others.


Written By

Vinod Kotiya




Comments

This blog post is absolutely amazing! At Sprwt we provide events booking software for catering businesses.

Popular Posts