Adam
Adam

Reputation: 4172

Handle multiple Google Sheet onFormSubmit in same Spreadsheet

Is it possible to handle multiple onFormSubmit events in the same spreadsheet? I have multiple forms linked to the same sheet effectively used as a database/webapp.

Here is the 'schema'

// first sheet
| client_id | name | is_something | is_another |
|-----------|------|--------------|------------|
| 1         | abc  | no           | no         |

// second sheet
| client_id | event |
|-----------|-------|
| 1         | value |

The use case is that one person in the org is gonna enter the data for the first sheet and another person will periodically look at all entries that don't have the "event" done yet and enter them when they are. At this point the first sheet needs updated to reflect the new boolean value. There are multiple forms that are submitted after the initial that need to update a column on the first sheet.

Is there a better way of doing this? Maybe app script web app? Eventually I'd migrate to App Maker but that isn't a general release yet.

Upvotes: 0

Views: 368

Answers (1)

Toma
Toma

Reputation: 589

I have tested this, works fine:

function onFormSubmit(){
  var as = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  switch(as.getName()){
    case "sheet_name_1":
      Logger.log("hi sheet 1 !");
      break;
    case "sheet_name_2":
      Logger.log("hi sheet 2 !");          
      break;
  }
}

change the sheet_name to your own sheet name and see if it works :D

Upvotes: 1

Related Questions