Skip to content
Advertisement

How can i skip “undefined”?

I want to create a script, which will be grouping all not empty rows. But, i have problem with checking getDepth or getRange when group doesn’t exist. I get “undefined” and i can’t create easy check like “if getDepth < 0 or “undefined”” because script stopping. Few years ago i created many scripts on VBA but this Apps Scripts a little bit hard for me, I’m newbie here) Can anyone help me?)

JavaScript

Advertisement

Answer

It’s not clear how are you getting "undefined", anyway, Sheet.getRowGroup() throws an exception if the group doesn’t exist:

JavaScript

Considering the above you might use try..catch

JavaScript

Resources

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