Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Pre-fill date item

I have been trying to find the right method to pre-fill the start date field in my Google Forms with the current date and time, but I failed to achieve this.

I think the createResponse(hour, minute) would be the best method, however I have absolutely no idea on where to include it in my script:

    function book1() {
var form = FormApp.getActiveForm();
var responses = form.getResponses();
var len = responses.length;
var last = len - 1;
var items = responses[last].getItemResponses();
////// var current= items[2].createResponse(10, 00);
var email = responses[last].getRespondentEmail();
var equipment = items[1].getResponse();
var datestart = items[2].getResponse();
var dateend = items[3].getResponse();
var cal = CalendarApp.getCalendarsByName(equipment)[0];
Logger.log('current '+current);
Logger.log(datestart);
Logger.log(dateend);
var start = new Date(datestart);
var end = new Date(dateend);
Logger.log('start '+start);
Logger.log('end '+end);

var allEvents = CalendarApp.getCalendarsByName(equipment)[0].getEvents(start, end);//Returns an array of events

if (allEvents.length < 1) {

var event = cal.createEvent(equipment, start, end)
.addGuest(email);

MailApp.sendEmail({
    to: email,
    subject: "Equipment " +equipment+ " booking confirmed",
    htmlBody: "Equipment " +equipment+ " available, please return it by " +dateend+ " and scan the QR code when returning it.",
  });

}

else {
  var blob = HtmlService.createHtmlOutputFromFile("calendariframe").getBlob();
  MailApp.sendEmail({
    to: email,
    subject: "Equipment  " +equipment+ " not available",
    htmlBody: blob.getDataAsString(),
  });
};
}

In my latest attempt, I encountered that error;TypeError: items[2].createResponse is not a function

Would you know how to make it work?

Knowing that pre-filling the date and time only simplifies the process of the form users, but that in some cases they will not use the current date and time as a starting time for booking.

Thanks a lot in advance!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda