Reputation: 139
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 :)
Upvotes: 1
Views: 296
Reputation: 18717
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:
range
var data = range.getValues();
array = [];
[["value1"], ["value2"], ...,]
. Note. It should be a 2D-Array.rangeTo
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/44021567/google-sheet-script-multiple-getrange-looping
Upvotes: 3