在Google表格脚本中输入错误(Type error in Google Sheet script)

编程入门 行业动态 更新时间:2024-10-27 19:28:23
在Google表格脚本中输入错误(Type error in Google Sheet script)

在Google表脚本编辑器中,我使用下面的代码在电子表格中插入编辑响应链接以及表单数据。

function assignEditUrls() { var form = FormApp.openById('xxxxxxxxxxxxxxxxxxxxxxxx'); //enter form ID here var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses'); //Change the sheet name as appropriate var data = sheet.getDataRange().getValues(); var urlCol = 3; // column number where URL's should be populated; A = 1, B = 2 etc var responses = form.getResponses(); var timestamps = [], urls = [], resultUrls = []; for (var i = 0; i < responses.length; i++) { timestamps.push(responses[i].getTimestamp().setMilliseconds(0)); urls.push(responses[i].getEditResponseUrl()); } for (var j = 1; j < data.length; j++) { resultUrls.push([data[j][1]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']); } sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls); }

虽然这应该工作到上周,当脚本现在运行时,我收到以下错误:

TypeError: Cannot find function setMilliseconds in object . (line 18, file "Code")

我们将非常感激地提出任何想法或替代解决方案。

In the Google sheet script editor, I'm using the code below to insert the Edit response link in the spreadsheet along with the form data.

function assignEditUrls() { var form = FormApp.openById('xxxxxxxxxxxxxxxxxxxxxxxx'); //enter form ID here var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses'); //Change the sheet name as appropriate var data = sheet.getDataRange().getValues(); var urlCol = 3; // column number where URL's should be populated; A = 1, B = 2 etc var responses = form.getResponses(); var timestamps = [], urls = [], resultUrls = []; for (var i = 0; i < responses.length; i++) { timestamps.push(responses[i].getTimestamp().setMilliseconds(0)); urls.push(responses[i].getEditResponseUrl()); } for (var j = 1; j < data.length; j++) { resultUrls.push([data[j][1]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']); } sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls); }

Whilst this was working as it should up till last week, when the script is now run I get the following error:

TypeError: Cannot find function setMilliseconds in object . (line 18, file "Code")

Any thoughts or alternative solutions would be gratefully received.

最满意答案

这段代码为我运行,没有任何问题,也没有修改,所以无论你的错误是什么,它都是临时的,或者不是这部分脚本。

编辑:再次尝试再次确认并且执行记录确认给我:'[14-11-18 23:17:52:820 GMT]执行成功[0.581秒总运行时间]'我看到了链接显示在电子表格中没有问题。

This code runs for me with no issues and no modification, so whatever your error is, it's either temporary, or not with this portion of the script.

Edit: Just tried it again to be doubly sure and the execution transcript is confirming for me: '[14-11-18 23:17:52:820 GMT] Execution succeeded [0.581 seconds total runtime]' and I'm seeing the links appear in the spreadsheet no issue.

更多推荐

本文发布于:2023-07-23 22:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238179.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   表格   错误   Google   script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!