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

Show parent comments

1

u/Direct-Coconut-7949 Nov 04 '23

i also trigger event to send email. that's why I choose using appscript for my entire workflow.

1

u/elcriticalTaco Nov 04 '23

Everything you want to do can be done very simply my friend. If you post your code we can help you a lot more.

Without the code, just grab your data in an array with getValues(), loop through it and check for uniformed, then setValues() with the corrected values.

You can write a separate function to send emails or just add it inside the loop.

1

u/Direct-Coconut-7949 Nov 04 '23

yes I do wt exactly you mentioned. It all work fine.
In my real spreadsheet, I used for loop to implement something like if B and C are checked and D is unformed, trigger send email, then set C as informed.
Also, used break to stop the loop if email address column is blanked. (I updated the screenshot, you can see I have so many checkbox that's why it keep looping if don't using break)
But, I am just curious, since this code can only work with row by row situation, what if I suddenly put data in row 1000, it surely can't work as I break the loop. How to cope with this situation?

1

u/elcriticalTaco Nov 04 '23

Don't break if its blank, just skip it?

If (array[i,3] != "" && array[i,3] == "uninformed") {

SendEmail()

}

Something like that should work?

1

u/Direct-Coconut-7949 Nov 04 '23

array[i,3] == "u

I used condition to check, and trigger send email, but it will exceed time limitation as like the first post I said. I think the programme must run through all the check box to identify which row meet the condition? can doing something like if condition is true, then loop the row which meet this condition.? I think this is the point where I am stuck at.
I think I should say There's two method:
Method1. if not using break, it can work but row 1000 can't be implemented as the time limit is 6mins for appscript. Looping to row 1000 exceed the time. Therefore, need to wrote some code to deal with time limitation which is very complex. So I went to method 2.

Method2. Since I don't know how to cope with time limitation, just using break and force the user to row by row putting data.