1

I wanted to create a form for data collection that included a field for image upload. I tried Google Forms, which natively doesn't support file upload, but I found this example: Form and file upload with htmlService and app script not working

I managed to configure it with image upload, BUT, native Google Forms does have a timestamp column on the Spreadsheet responses.

I tried:

var timestamp = theForm.getTimestamp();

But didn't work...

How can I get the response timestamp?

Code excerpt:

function processForm(theForm) {
  var fileBlob = theForm.myFile;
  var folder = DriveApp.getFolderById(folderId);
  var doc = folder.createFile(fileBlob);

  // Fill in response template
  var template = HtmlService.createTemplateFromFile('Thanks.html');

  var name = template.name = theForm.name;
  var email = template.email = theForm.email;
  var timestamp = template.timestamp = theForm.getTimestamp();

  // Record submission in spreadsheet
  var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0];
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[timestamp,name,department,message,email,fileUrl]]);

  // Return HTML text for display in page.
  return template.evaluate().getContent();
}
Community
  • 1
  • 1
Silva
  • 161
  • 1
  • 12

1 Answers1

4

HTML forms do not automatically pass any timestamp to the server on submit, like Google Forms do. You will have to generate that timestamp yourself. new Date() will do what you want:

var timestamp = template.timestamp = new Date();

If you need to output this date object to screen in your page, you will need to make it human-readable by formatting it. You can use Utilities.formatDate() method to do this.

azawaza
  • 3,065
  • 1
  • 17
  • 20
  • That worked, thanks. But isn't this the client side timestamp? – Silva Oct 04 '14 at 19:36
  • 1
    No, .gs Google Apps Script files are processed and executed on the server, not in the client's browser. So the timestamp will be the server timestamp. You should make sure your GAS project has correct time zone selected on _Info_ tab under menu File->Project properties. – azawaza Oct 06 '14 at 18:32
  • Oh, thanks for the info. I have no experience with GAS. Thank you! – Silva Oct 07 '14 at 20:59