0
votes

I want to run a function when a google sheet is opened for which i am trying to call a function using function onOpen(e)

but I get error when i try to debug

Missing { before function body. (line 8, file "Code") (row where function UpdateColData is called)

here is my code:

function onOpen(e) {
  SpreadsheetApp.getUi()
  .createMenu('Scripts')
  .addItem('test', 'Test1')
  .addToUi();


function UpdateColData();

  }



4

4 Answers

0
votes

Your missing a { on line 8 or you did not intend to write the second one function UpdateColData(); or function UpdateColData(){}

0
votes

Look at the line function UpdateColData();. The syntax error is saying that you did not open the function definition with a "{" like so:

function UpdateColData() {
}

What you supplied was invalid javascript

0
votes

Try this:

function onOpen(e) {
  SpreadsheetApp.getUi()
  .createMenu('Scripts')
  .addItem('test', 'Test1')
  .addToUi();
  UpdateColData();

  }

function UpdateColData() {
  //function definition
}

Assuming that you are doing nothing that requires authorization in UpdateColData() then this should work. Although it sounds like you're updating data so my guess is that this won't work because simple triggers cannot perform actions that require authorization. You will have to use an installable trigger

0
votes

You don't call a function by using the word function:

function onOpen(e) {
  SpreadsheetApp.getUi()
  .createMenu('Scripts')
  .addItem('test', 'Test1')
  .addToUi();

   UpdateColData();

  }