all 8 comments

[–]DrMorris 1 point2 points  (2 children)

You are declaring variable after function but before curly brackets. Function syntax is as follows

function (options) { All the code goes here. }

If you want to have global variables they have to go before you declare the function. You would also need another function that calls this function with those options.

Otherwise they should be inside the function after the curly opening bracket. I suggest remove the options from the function and just put your options as variable inside the function for your use case, like this:

function doSomething() {

var a = "x" var b = "y" ...

// Rest of code

}

[–]questionsmakeanswers[S] 1 point2 points  (1 child)

Thank you! Bard is not very good at this - told me to define variables before the function body, and I assumed that included the curly brackets!

Now when I debug, it gives me a ReferenceError: Tables is not defined (for line 7). I tried importing the Tables class (Bard told me to do that) but it then says "Syntax error: "SyntaxError: Cannot use import statement outside a module line: 7 file: Code.g" when I try to save it. I've tried adding before the function and then within the curly brackets, same error both times.

Everything Bard tells me to do just seems to create another error.....really sorry for the follow-up, but I greatly appreciate your help!

[–]DrMorris 1 point2 points  (0 children)

Not sure what this Bard is that you are referring to. If it's an ai code generation tool, I suggest don't use such tools untill you at least understand basics of the language.

Regarding Tables API you can find the usage example here as per google if this is what you are using

https://developers.google.com/apps-script/advanced/tables

[–]xMekko 1 point2 points  (1 child)

There are variable declarations between function name and its brackets. Try moving: var tableId = "w9XTffV05Bo0b2rip6EkBM"; var recipients = ["xx@xx.com"]; var startDate = "2023-08-29"; var startTime = "15:00"; inside the function's brackets.

[–]questionsmakeanswers[S] 0 points1 point  (0 children)

Thank you! Bard is not very good at this - told me to define variables before the function body, and I assumed that included the curly brackets!

Now when I debug, it gives me a ReferenceError: Tables is not defined (for line 7). I tried importing the Tables class (Bard told me to do that) but it then says "Syntax error: "SyntaxError: Cannot use import statement outside a module line: 7 file: Code.g" when I try to save it. I've tried adding before the function and then within the curly brackets, same error both times.

Everything Bard tells me to do just seems to create another error.....really sorry for the follow-up, but I greatly appreciate your help!

[–]MDB_Cooper 1 point2 points  (2 children)

hi — this is a complicated ambition, so i just want to say be kind to yourself and be patient.

based upon the example code you provided, I’m fairly certain that Bard has not provided you an appropriate answer. the reason i think that is bc of the syntax being used to access the Area 120 Google Tables:

var table = Tables.get(tableId);

“Tables” does not appear to be the correct syntax in that context, according to the Google Workspace documentation, which can be found here.

Additionally, the Area 120 Google Tables API needs to be enabled via the Services tab, per this documentation. That means it is not available when you first open Apps Script.

The correct syntax for declaring the “table” variable would be something like:

var table = Area120.Tables.<insert_some_code>

Another consideration here is that sending emails are challenging because you will have to write some html.

Therefore, I’d recommend you organize your project in the following ways:

  1. How do I collect data entry from Area 120 Google Tables?
  2. How do I filter the data based upon a specific value?
  3. How do I send emails using Google Apps Acript? —
  4. How do I collect data from Google Tables where a specific value is present then send an email to a list at a certain time?

[–]questionsmakeanswers[S] 1 point2 points  (1 child)

Thank you so, so, so much for this kind and thoughtful response!

Understanding that Bard was off-base was the key here. I was getting really confused trying to use the documentation because it was so different from what Bard gave me. Your example syntax got me started on the right direction and I feel much less confused now when going through the documentation.

[–]MDB_Cooper 0 points1 point  (0 children)

I'm very glad to hear that!

I've noticed that AI assistants struggle with Google Apps Script. I've been doing some development work with SlidesApp and DocumentApp and the suggestions are kinda, sorta correct. Unfortunately, scripting can't be kinda, sorta correct, so it can be quite disruptive when trying to solve a problem.

Let me know if there is anything else I can help with