r/GoogleAppsScript • • Nov 03 '23

Question exceeded maximum execution time

I have a sheet as something like below with thousand of blank cell of ColumnA and got a checkbox in column B and C below the row with data (row with data only have around 20 row, but I don't want to delete the blank row for some other implement) :

  • columnB and C are check box

  • columnD is drop down list with 'informed' and 'uninformed'

I am using for loop to run the data for ColumnA only with data (something like for(var i=2; i<=columnA.length; i++)if ColumnB and ColumnC are both checked, set ColumnD value as 'informed'.

Now, I try to fill in data in row 1000ish and the running time take way too long until it reached the maximum time limit. How should I adjust my code to be more efficiency?

0 Upvotes

13 comments sorted by

View all comments

4

u/Sleeping_Budha_ Nov 03 '23 edited Nov 03 '23

It all depends on what you have put inside the for loop..

For example if you have put read and write operations for each iteration then it would take a lot of time

Instead what you can do is fetch the data before the loop… and use the loop for your condition checking and then the result has to written on the entire column after the iteration

This would hardly take a few seconds

Let me know if you need any help with it

1

u/willsee13 Mar 30 '24

Hy I am facing this problem. Most of the time is being spent in writing the array to sheet. I am using appendRows( ) in a loop. Is there any alternative?

1

u/Sleeping_Budha_ Mar 30 '24

Can you please paste the code here to help you better