Skip to content
Advertisement

same function works in one script but doesn’t work in another script although copy pasted :(

I wrote a function that works in one application script for one spreadsheet and then copy pasted it into another application script for another spreadsheet where it doesn’t work and I get error: Error
Exception: The number of rows in the range must be at least 1. (anonymous) @ Code.gs:5

Function is:

JavaScript

And works well in a simple .gs project where this function is the only function in .gs project for sheet: https://docs.google.com/spreadsheets/d/1cEpLk-jEgWCIfSwzEj5X0n3Q1OOJ_5MJr5vT257BHgI/edit?usp=sharing

But when I copy paste it in another .gs project where it is not the only function in that project it stops working and throws an error:

Error
Exception: The number of rows in the range must be at least 1. (anonymous) @ Code.gs:5

This happens in a script:

JavaScript

And it doesn’t work (does not create a dropdown) in a spreadsheet: https://docs.google.com/spreadsheets/d/1ZXACv6TfPQuy9zmOIjIpNm1RVfpDaoBx5sIQGnOuPiQ/edit?usp=sharing

Any idea and hint very much wellcomed 🙂 tnx.

Advertisement

Answer

If you want to call function validate() with onEdit trigger and you want that function validate() creates a dropdown with items from another spreadsheet, then you have to change onEdit function from simple trigger to instalable triger because simple trigger cannot access data from another spreadsheet. Only instalable trigger can do this. That’s why length of the range was 0 and you were getting the error.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement