Check empty Spreadsheet in Google Spreadsheets

Hi there, I am reading Data from a Google Spreadsheet and displaying it in a list view, though when the Spreadsheet is empty I need to display a warning message in the ListView indicating there is no data available. I have been able to write the following script that checks for Data in the Spreadsheet returning a True or False value, though I still have not been able to implement my blocks to connect with the script. Could anyone please be so kind to give me some clue as to how implement this behavior?

function checkEmptySpreadSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A1:A1");
Logger.log(range.isBlank());
}

Probably easier to check what comes back from your HTTP GET request / query to the google sheet in the app - i.e. check the contents of responseContent...?

1 Like

Hi, thank you very much for your response, I have tried to work with your suggestion but I still can't make it work as desired, here are my blocks, could you please take a look at them and let me know what I am doing wrong?

blocks

If you check my previous post I suggested to check the responseContent - NOT the responseCode.

Try like this:

In the Web1.Url the gid = 0 because it is the first sheet, check the gid number if a different sheet.
I put the output list to a label for debugging - you would normally set the output list to variable.

1 Like

@TIMAI2 Thank you very much, this is just what I need, my coding knowledge is very limited but with your help I am getting better. :slight_smile:

I have been experimenting with the code and since the table in my Spreadsheet is using the first row for the headers it needs to be excluded from the logic, I have tried to get this behavior by including a remove list item block though when running the code I get an error message indicating it cannot accept the arguments in the Spreadsheet. Is there another way to ignore the first row in the Table?

you need to create the AI2 list first, then you can remove the first row

1 Like

Hi, I have modified my blocks accordingly as indicated, the code is working though the only thing I can't figure out is why after running the code on an empty Spreadsheet with only the headers in place instead of getting my coded warning message I get a small character resembling a rectangle.

When I run the code on a totally empty Spreadsheet I get the desired behavior, that is I get my coded warning message.

I am attaching my blocks and a couple of screen captures of the result I am getting.

Results for a Spreadsheet with headers

Results for a totally empty Spreadsheet with no headers

It is not a rectangle, it is opposing square brackets, [ ], indicating an empty list exists. If you want to return this as no Data as well, then an additional if condition will be required.

Something like this:

Great, I will use this in my app, thank you very much :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.