[英]For Loops timing out: JavaScript / Google Apps Script
So I am have this issue with Google Apps Script. 所以我对Google Apps脚本有这个问题。 It is timing out because the app server requests are taking too long.
它超时是因为应用服务器请求耗时太长。 I was just wanting to see if my coding could be cleaned up a bit to run faster or is there another method which would work?
我只是想知道我的编码是否可以清理一下以便更快地运行,还是有另一种方法可以工作?
Code below: 代码如下:
for (var y = 1; y < listLast ; y++) {
var matchor = listSheet.getRange("B" + y).getValue();
var listEmCo = listSheet.getRange("A" + y).getValue();
if(matchor == "Match") {
Logger.log("Do Nothing");
} else {
for (var x = 0; x < formLast; x++) {
if(listEmCo == formData[x]){
listSheet.getRange("B"+ [y]).setValue("Match");
break;
} else {
listSheet.getRange("B"+ [y]).setValue("No Match");
}
}
}
}
Thanks for any responses :) 谢谢你的回复:)
Do not use .getValue();
不要使用
.getValue();
in a loop. 在一个循环中。 This operation is heavy.
这个操作很重。
Please use range.getValues()
and then loop the array to get values. 请使用
range.getValues()
然后循环数组以获取值。
The plan is: 计划是:
range
range
var data = range.getValues();
var data = range.getValues();
获取数据var data = range.getValues();
array = [];
array = [];
[["value1"], ["value2"], ...,]
. [["value1"], ["value2"], ...,]
。 Note. rangeTo
rangeTo
rangeTo.setValues(array);
rangeTo.setValues(array);
to paste new values. See more: 查看更多:
See more questions on topic: 查看有关主题的更多问题:
http://stackoverflow.com/questions/39859421/google-script-internal-error-after-15-seconds http://stackoverflow.com/questions/39859421/google-script-internal-error-after-15-seconds
http://stackoverflow.com/questions/39586911/google-script-exceeded-maximum-execution-time-help-optimize http://stackoverflow.com/questions/39586911/google-script-exceeded-maximum-execution-time-help-optimize
http://stackoverflow.com/questions/38618266/google-sheet-script-times-out-need-a-new-way-or-flip-it-upside-down http://stackoverflow.com/questions/38618266/google-sheet-script-times-out-need-a-new-way-or-flip-it-upside-down
http://stackoverflow.com/questions/44021567/google-sheet-script-multiple-getrange-looping http://stackoverflow.com/questions/44021567/google-sheet-script-multiple-getrange-looping
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.