0

I am very new to Google Apps Script, but I have previous experience creating Google Forms. I created a Google Form in which the first input is "Date". I want to have the current date pre-filled as soon as the Google Form opens without using pre-filled URLs. Is there a way to use the onOpen trigger to pre-fill this field with the current date?

Please see below for the code I wrote so far (I commented out the last two lines because I kept getting an error message while running this function). Overall, I want to call this function every time the Google Form opens, before the user starts filling out the form.

function inputDate(){
     var formattedDate = Utilities.formatDate(new Date(), "PST", "yyyy-MM-dd");
     Logger.log(formattedDate);
     var form = FormApp.getActiveForm();
     var formResponse = form.createResponse();
     var items = form.getItems();
     var formItem = items[0].asDateItem();
     //var response = formItem.createResponse(formattedDate);
     //formResponse.withItemResponse(response);
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 1
    Welcome. This is not possible. – Rubén Apr 14 '20 at 03:18
  • Fantastic! An impossible problem to tackle as my first post. I currently have the google form set up as an optional input, so users can leave it blank. My plan B was to edit it on the Google Sheets side using the onFormSubmit trigger. Essentially (no code yet): If new Row has blank date, input current date, else do nothing. Thoughts? – Albert Chu Apr 14 '20 at 04:10
  • Consider the following: if the "date" is blank use the date part of the timestamp. – Rubén Apr 14 '20 at 04:22
  • That was my original workaround, but I wanted to see if there was another way. Thanks for the quick clarification! – Albert Chu Apr 14 '20 at 04:50

0 Answers0