To set up a delay on the execution of a Google Apps Script use the method sleep(milliseconds) of Class Utilities.
I'm intentionaly not including an example of using this method here because this question is about custom function (a Google Apps Script function used in a Google Shees formula), keep reading.
The above will work between code sentences and might be helpful in "regular scripts" to reduce the rate to call a method, i.e. when using UrlFetchApp.fetch(url)
, deleting rows, among other cases but not when the problem occurs when using a formula paterns that is repeated thousands of times (i.e. when writing a formula in A1, an then doing fill down or copy paste to copy the formula to whole column)
It's very likely that you should try to convert your custom function from one that returns a single value into one that is able to get and return an array of values. See Optimization.
Note: If a custom function like Vidar S. Rambal's answer to the referred question by the OP, it doesn't make sense as the it only calls a method.
/**
* @customfunction
*/
function encode(value) {
return encodeURIComponent(value);
}
Instead of repeating the same formula multiple times,
|
A |
1 |
=encode(A1) |
2 |
=encode(A2) |
you might use
by using the following declaration for the custom function:
/**
* @customfunction
*/
function encode(input) {
return Array.isArray(input)
? input.map(row => row.map(cell => encodeURIComponent(cell)))
: encodeURIComponent(input);
}
but when the formulas are not contigous, then it might be better to use a "regular" script called from a custom menu or by using a trigger.
Related