对于循环超时:JavaScript / Google Apps脚本 [英] For Loops timing out: JavaScript / Google Apps Script

查看:122
本文介绍了对于循环超时:JavaScript / Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Google Apps Script中遇到了这个问题。它正在超时,因为应用程序服务器请求时间太长。我只是想看看我的代码是否可以清理一下,以便运行得更快,或者是否有另一种方法可行?



以下代码:

$ (var y = 1; y
var matchor = listSheet.getRange(b
$ b

  B+ y).getValue(); 
var listEmCo = listSheet.getRange(A+ y).getValue();
if(matchor ==Match){
Logger.log(Do Nothing);
} else {
for(var x = 0; x
if(listEmCo == formData [x]){

listSheet.getRange(B+ [y])。setValue(Match);
休息;
$ b} else {

listSheet.getRange(B+ [y])。setValue(No Match);




$ b code


$ b

感谢您的回复: code>在循环中。这个操作很重。

请使用 range.getValues(),然后循环数组以获取值。 / p>

计划是:


  1. 取得初始范围

  2. 使用获取数据> var data = range.getValues();

  3. 使空数组写入新值 array = [];

  4. 循环数据并创建新数组,正确的值 [[value1],[value2],...,] 注意它应该是2D数组。

  5. 循环定义一个范围来粘贴新值: rangeTo
  6. 使用 rangeTo.setValues(array); 来粘贴新值。
  7. ol>

    查看更多:





    标签#另一个获取数据范围问题



    查看更多关于主题的问题:



    http://stackoverflow.com/questions/39859421/google-scrip t-internal-error-after-15-seconds



    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 / 44021567 / google-sheet-script-multiple-getrange-looping

    代码运行太慢


    So I am have this issue with Google Apps Script. 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(); in a loop. This operation is heavy.

    Please use range.getValues() and then loop the array to get values.

    The plan is:

    1. get the initial range
    2. get data with var data = range.getValues();
    3. make empty array to write new values array = [];
    4. Loop the data and make new array, fill it with proper values [["value1"], ["value2"], ...,]. Note. It should be a 2D-Array.
    5. After the loop define a range to paste new values: rangeTo
    6. Use rangeTo.setValues(array); to paste new values.

    See more:

    Tag #Another-get-data-from-range-question

    See more questions on topic:

    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/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

    Code runs too slow

    这篇关于对于循环超时:JavaScript / Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆