简体   繁体   English

如何在Google表单中将默认日期设置为今天?

[英]How to set default date to today in google form?

I need to set in a google form response the today date (Not hardcoded) when submited 提交时,我需要在Google表单响应中设置今天的日期(未硬编码)

I'm accesing the form, adding a date question, setting the title and the help text, but nothing more 我要填写表格,添加日期问题,设置标题和帮助文本,但仅此而已

function myFunction() {
    var myForm = FormApp.openById("MyFormID");
    var formDate = myForm.addDateItem();
    formDate.setTitle('Ciclo');
    formDate.setHelpText('Ciclo de registro');
    //This is doing nothing at all
    //var formDateResponse = formDate.createResponse(new Date());
 }

Im only getting the date question unfilled 我只得到日期问题未填补

A FormResponse has a getTimestamp() function built into it. FormResponse具有内置的getTimestamp()函数。

If you are using an onSubmit Trigger you can get it by: 如果您使用的是onSubmit触发器 ,则可以通过以下方式获取它:

function onSubmit(e){
  var response = e.response;
  var timestamp = response.getTimestamp(); //Date Object!
}

It's important to note that if you have an onSubmit Trigger in Google Sheets it does not provide the e.response FormResponse object, but instead a values array, namedValues array, or range object. 请务必注意 ,如果Google表格中有onSubmit触发器,则它不会提供e.response FormResponse对象,而是提供一个值数组,namedValues数组或range对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM