last day (15 days later) » 

12:37 AM
1
Q: Why Class Range getValues sometimes returns [[]] when chained to Class Sheet getActiveRange?

RubénTl;Dr. Is a good practice chaining getValues() to Class Sheet getActiveRange() ? What could cause that sometimes returns [[]] instead of the expected values? This is derived from Get selected values in row where I posted an answer with a couple of alternatives to get the values of the active ...

 
When I tested your flow from 1 to 11, at 10 Open the Log. [[]] were logged instead of the expected values., the values of the active range can be seen at log. I think that this is different from your situation. So I thought that my understanding might no not correct. I apologize for this. Can you confirm your flow in your question again? Or for example, when SpreadsheetApp.getUi().alert(JSON.stringify(values)) is put to myFunction2(), the same result with the log will be retrieved?
Unfortunately, I cannot still replicate your situation. I'm sorry. So I would like to confirm your flow and situation for replicating your issue. At 7. Open the Log, what result did you confirm at the log? And I understood that the function of 9. Run the function is myFunction2(). Is my understanding correct? For example, in your situation, when getA1Notation() and getSheet().getSheetName() are used instead of getValues(), what result will you get?
 
@Tanaike The problem apparently occurs "randomly". One detail that might be relevant is that the flow described was realized after more than 12 hours since the last time I used Google Sheets and the Apps Script editor.
 
@Rubén thanks, I managed to reproduce, followed by "Could not connect to server" error, btw - looks like a bug... Or not - how do you select the row?
 
@Tanaike and Oleg I updated the question including some notes that answers your qustions (I will delete my related comments)
 
Any answer to For example, in your situation, when getA1Notation() and getSheet().getSheetName() are used instead of getValues(), what result will you get?
 
12:37 AM
@Tanaike Rearding getA1Notation() and getSheet().getSheetName() today they are returning the expected values.
 
Too bad. Wished the error stayed and we could see what A1notation of the range was. The empty values [[]] shouldn't be valid for any range.
 
Thank you for adding more information. Unfortunately, I cannot still replicate your situation in 15 tests with updated flow. Also, now I tested the script created in yesterday. But I cannot replicate it. I think that as you say, this situation randomly occurs. From your latest replying, it seems that although the active cells are correct, the correct values corresponding to the active cells cannot be retrieved. I think that this is a bug. So how about reporting it to the Google issue tracker? By this, when Google side think of this as the important information, this might be investigated.
 
@Tanaike Thank you :) Do you have a suggestion regarding how to catch this kind of failures? I though that the optional chaining operator could be used but Google Apps Script editor throws a syntax error and doesn't allow to save the .gs file.
 
@TheMaster - from what I've seen, this [[]] array is returned consistently if you select an empty cell, so, for some ranges, it is by-design - and if it sometimes would return an empty array, and sometimes a 2D one, it would be an inconsistency (that said, I agree that in practice it is of little importance as it does not cause errors).
 
@OlegValter this [[]] array is returned consistently if you select an empty cell Consistently? How? What do you mean by empty cell? It should return a [['']] for empty cells not a empty array.
 
12:37 AM
Although this might be not good method for leaving to chance, for example, I think that when you can record the situation of the issue as the animation gif, it can be the convincing data for explaining the issue. Using this and your flow in your question, it describes that this issue randomly occurs.
 
@TheMaster - I mean that it is returned 100% of the time when it is expected (as opposed to randomly), I do not mean that this is a necessarily good decision, though. To reproduce: select a cell without any value, then run the function in question. If it returned a [['']] array it would be better, I argree (come to think of it, now this is an inconsistency, as for ranges > 1 cell empty ones are returned as empty strings)
 
@OlegValter It is never expected. If it comes, it's a bug. I'll try to repro.
 
@TheMaster - I simply explained that I use "consistently" in a strict sense: "in a way that does not vary", I don't think this is correct behavior (I thought you wanted it to return just an empty array). Seems easily reproducible for me - responds with [[]] every time I run the function. And this probably a bug indeed from docs: "Empty cells are represented by an empty string in the array"
 
@OlegValter Are you using json.stringify? Otherwise inbuilt logger won't show it correctly. Tested. No repro.
 
@TheMaster - no, just what is directly displayed in the logger and executions tab. Setup - default GCP, V8. I have a screenshot as proof
 
12:37 AM
@OlegValter Honestly all should pay extra close attention to all Tanaike comments. Or for example, when SpreadsheetApp.getUi().alert(JSON.stringify(values)) is put to myFunction2() You should always stringify. What you can see [[]] means nothing. If you at least check length of inner array, I believe it should show 1 and not 0. situation, when getA1Notation() and getSheet().getSheetName()
 
1:06 AM
Ok, Samuel moved the rest of the discussion to chat as well, now we have 2 chats! Moving my next replies here:
@TheMaster and afaik logger (now connected to Stackdriver) should return a JSON string without extra shenanigans. That said, I rarely use it for debugging - I will take note of @Tanaike's suggestion and use it
 
1:51 AM
@Rubén - well that is an interesting development, the post got comment-locked :) Also @TheMaster @Tanaike - in the case of the consistent empty cell the actual value is indeed an empty string
 
2:32 AM
@OlegValter Thank you for testing it. In that case, I think that it's the bug. But unfortunately, I cannot still replicate it. 😅
 
3:08 AM
@Tanaike I cannot replicate it too 😂 I only tested the case where the empty array of arrays is displayed consistently (with empty cells)
 
3:27 AM
@OlegValter This might be the randomly bug. But I want to believe that such information is important for Google side.
 
3:55 AM
@Tanaike The issue, I believe is @Rubén was opening a couple of other webpages for authorization and stuff => This stopped whatever was pinging Google servers from Google sheets web page about the active sheet and active range (@OlegValter theory) => the first row, first col A1 is automatically used by default,
which is empty as seen in his screenshots=> [[]] is logged. If A1 in first sheet had something: first=> then [["first"]] would've been logged. I think the issue is repro, if Google sheets is closed and the code is run from the editor only after modifications for error if it happens.
Has anyone tried Firefox?
 
 
2 hours later…
5:36 AM
@TheMaster probably, it is a pity I cannot reproduce the issue at all, and we lack information on networking during the time the issue happened
@TheMaster do you think it will make a difference? I asked @Rubén about the setup, and they have latest Chrome
@TheMaster I apologize if I misunderstood you, but how does one keep editor of the bound script open while the corresponding GSheet is closed? Afaik it is autoclosed as well
 
6:16 AM
@OlegValter Can't you just open the bound script link?
 
6:36 AM
@TheMaster we could do that all this time? :facepalm: Thank you!
 
 
1 hour later…
7:44 AM
@TheMaster Thank you for your consideration. Now I could understand about your comment. In that case, I understood that the opened script editor is not linked to the active Spreadsheet. Using this situation, I could replicate the situation as "A1" of the active range.
So in order to success to run the script every time, at first, open the Google Spreadsheet and select the range and open the script editor from the opened Spreadsheet and run the script. Or, it is to execute to run the script using the custom menu.
 
@Tanaike Don't think the issue is reproducible if you use custom menu. Because then the sheet is active and has a range.
 
@TheMaster Yes. So, that is the method for successfully running the script every time without this issue.
 
@Tanaike Yes. I came to the same conclusion.(if active* methods are used)
 
@TheMaster In that case, I think that it is not the bug.
 
@Tanaike I actually didn't have luck with the first method( select range first=> open script editor) in Firefox. Custom menu and others work fine though
 
7:58 AM
@TheMaster Now I can test this using only Chrome. But as you say, in this case, I also think that the dependences of browser might occur.
 
@Tanaike Agree. I'm just saying. Best way is to custom menu or macros or any method that leaves the spreadsheet in focus and NOT in background
2
 
@TheMaster 👍
 
@Tanaike 👍
 
@TheMaster Today, I could obtain the new experience. So today is good day for me. Now, I have to be away from here. It's good evening in Japan now. So I want to prepare dinner and also eat it!
 
@Tanaike what's for dinner?
 
8:05 AM
@TheMaster I think that it will be the Japanese noodle which is the somen noodles. In Japan, this is often eaten every summer.
@TheMaster I'm away. Thank you for nice discussions!
 
8:20 AM
@Tanaike Bye. Enjoy your dinner
 
 
13 hours later…
8:53 PM
@Tanaike, @TheMaster @OlegValter Thank you very much
 
@Rubén and thank you for discussion - did you manage to find anything since then, btw?
 
The assumption that I have several web pages opened when the problem occurred is correct, and I was switching from SO to the spreadsheet and the GAS editor, so I think that it's very likely that at some point the spreadsheet went to "somewhere" but the selected range was kept selected all the time.
@OlegValter Not something really important...
just that in another project I switched to the old runtime because it was impossible to debug it using V8...
Several times the debugger just hanged, other times got "Can't connect to server"
 
@Rubén yeah, I guess that's the only reasonable explanation - although I kept tabs on the test spreadsheet, and it does not seem to matter whether there were any disruptions in networking. Also, I could not find any cache hits issues with cache enabled
@Rubén well, just a peculiar issue - if there was only one person experiencing it, it would not be worth it, but at least two, and sporadically, and on the new runtime - that's interesting...
 
Based on other questions where getActiveRange() chained to Class Range methods was not working and the responses usually offered alternatives that don't use chaining, i think that chaining should be avoided with "active" methods.
 
@Rubén that one I also got a couple of times, btw. "can't connect to server" seems to happen absolutely at random (from the client-side pov)
 
9:03 PM
@OlegValter The related issue on the issue tracker has a lot of +1
 
@Rubén btw, which one do you refer to, I am not sure I know of it (I know of a similar one: issuetracker.google.com/issues/149636786)
 
Another symptom on my side is that usually developers.google.com pages takes a lot of time to load but pages from other sites don't.
 
9:23 PM
@Rubén oh, thank you, good read (if one can apply the term here), I was not aware of the thread. Not to step on anyone feelings, but I think the web ide should be scrapped in favour of local IDEs of choice, I rarely do debugging there these days
 
9:35 PM
@Rubén hm, lightning-fast for me (and I have cache disabled), maybe you are unlucky with the region serving requests from your location...
 

last day (15 days later) »