谷歌表单提交脚本

时间:2014-06-01 02:03:28

标签: google-apps-script google-sheets

在表单提交中,我试图获取电子表格中记录号单元格集的值。但即使记录器显示正确的值,我在确认消息中得到的值也不正确。

        /**
        * Gets the list of responses and display the recordNumber from the spreadsheet
        * 
       */

          function ticketNumberAlert() {
               var form = FormApp.getActiveForm();

               Logger.log("form name " + form.getId() + " " + form.getTitle());
               Logger.log("form destination " + form.getDestinationId() + form.getDestinationType());

               var sheet = SpreadsheetApp.openById(form.getDestinationId());

               var lastRow = sheet.getLastRow();

               Logger.log("Record Number " + lastRow);

               var lastItem = sheet.getRange('I'+lastRow).getValue();

               var newRecNum = lastItem + 1;

               Logger.log("last record number" + newRecNum);

               //form.setConfirmationMessage('Thanks for registering. Your ticket number is ' + lastItem );

               form.setCustomClosedFormMessage('Thanks for registering. Your ticket number is ' + newRecNum );

    }

确认消息显示#15。但是日志显示正确递增的recordNumber值。

[14-06-01 07:06:41:430 EDT]表格名称1gIxWfEQIYHSkxZQbjJHa2CTdHO8mAFwQPcBJiiEHAC8
[14-06-01 07:06:41:529 EDT]表格目的地0AgZ_Q0okrzbJdG9CbzdKQTJXYTdWOXdrbWpyeWFUVlESPREADSHEET [14-06-01 07:06:42:008 EDT]记录号18 [14-06-01 07:06:42:045 EDT]最后一个记录号19

1 个答案:

答案 0 :(得分:0)

我应该使用setConfirmationMessage而不是setCustomClosedFormMessage。 CustomClosed表单消息是表单不接受任何更多响应时显示的消息。