D
D
Dmitry Shalimov2019-08-19 14:29:39
JavaScript
Dmitry Shalimov, 2019-08-19 14:29:39

How to make google forms script work on form submission?

They asked me to write a script for adding an entry to the calendar using Google Forms... I sat down and looked at ready-made solutions, for the most part the functionality was suitable, but some important part still disappeared... I decided to look at how to write my own, and it seems like even something it worked, it just doesn't work!
In fact, this script should pick up information from the form and send it to the calendar, but for some magical reason of my total lack of experience, there is no result.

function create_event() {
  var calendar = CalendarApp.getCalendarsByName("Delivery")[0];
  
  var data = get_data();
  
  var title = data[0];
  var startTime = data[1];
  var endTime = data[2];
  var options = data[3];
  
  calendar.createEvent(title, startTime, endTime, options);
  
}

function get_data() {
  var form = FormApp.getActiveForm();
  var responses = form.getResponses();
  var response = responses[responses.length - 1];
  
  //var email = response.getRespondentEmail();
  
  var items = response.getItemResponses();
  var title = items[2].getResponse();
  var description = items[7].getResponse();
  var startTime = formatDataTime(items[0].getResponse());
  var endTime = formatDataTime(items[1].getResponse());
  
  var options = {
    sendInvites: true,
    description: description,
  //  guests: email
  };
  Logger.log([title, startTime, endTime, options]);
  return [title, startTime, endTime, options];
}

function formatDataTime (dateTime){
  //var dateTime = "2019-08-19 19:00"
  var date =  dateTime.split(" ")[0].split("-");
  var time =  dateTime.split(" ")[1].split(":");
  
  var year = date[0];
  var mouth = date[1];
  var day = date[2];
  
  var hour = parseInt(time [0], 10);
  var minute = parseInt(time [1], 10);
  var second = 0;
  var millisecond = 0;
  
  var new_date = new Date(year, mouth, day, hour, minute, second, millisecond);
  Logger.log[new_date];
  return new_date;
}

https://docs.google.com/forms/d/1z_zArEyjOUiHZHgar...
I tied up a script launch trigger, and it seems like everything should work, but the script is not being written...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2019-09-03
@ProgrammerForever

If the code has not been run manually before, then you need to run and allow Google to work with this script. With user-defined functions in tables, the same trouble - until you run it hand-to-hand from the code editor - they do not work in a table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question