Form Submit Not Triggering Google Scripts

I am trying to get google sheets to trigger a onEdit script when a form is submitted by identifying when a column changes. I can type in the column and it triggers the script but when I have a form submit data to the column it does not trigger. Any ideas.

Here is the script I’m running:

function onEdit(e) {
var langName = ‘ADVISOR INFORMATION’
var langCell = ‘C2’
var curSheet = e.range.getSheet()

if (curSheet.getName() === langName) {
if (e.range.getA1Notation() === langCell) {
var cookingMethodSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(‘APPOINTMENTS’)
var range = cookingMethodSheet.getRange(‘D2:N2’)
range.clear()
}
}
}

Hi Joe, is this the problem?

The problem with onChange() is that it would be performed everytime something in the workbook is changed not just the sheet the forms are submitted to. Unless I’m mistaken and you can do a onchange with just a single sheet

Wrap a further IF to make sure it only triggers for a certain sheet.

For example:

function sendEmail(e) {
   var Active = e.source.getActiveSheet().getName();
    if(Active == 'SheetA'){

What I meant to say is that I don’t think it’s possible to setup onChange to just look at one tab and not the entire workbook/sheet.

Yeah I understood that. You can try my method above, wrap an IF so that it is only triggered when the active sheet is the sheet of your choice.

Taking my original script above could you try to modify it with on change and I can see if it works.

function ClearRows(e) {
var Active = e.source.getActiveSheet().getName();
if(Active == ‘ADVISOR INFORMATION’){
var langCell = ‘C2’

if (e.range.getA1Notation() === langCell) {
var cookingMethodSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(‘APPOINTMENTS’)
var range = cookingMethodSheet.getRange(‘D2:N2’)
range.clear()
}
}
}
}

Can you try this and tell me if it works?

I’m sorry. I live in the states and it got so late I just took another stab at it and got it working then went to bed. This is the script I made that got it to work though:

function onChange(e) {
var sheet = e.source.getActiveSheet()
if (sheet.getName() === ‘ADVISOR INFORMATION’) {
var cookingMethodSheet =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(‘APPOINTMENTS’)
var range = cookingMethodSheet.getRange(‘D2:N2’)
range.clear()
}
}

Thank you for your help and your time.

1 Like

No worries, have a nice Sunday yourself. Now my time to go to bed, it’s 11pm in Vietnam :smile:

It’s pretty much identical to be honest…I just eliminated a variable. And I needed it to check the entire page, I used that variable for testing. That’s the only reason I had it on there.

1 Like

Real quick, do you know if it’s possible to make glide return to the home page/default page after a form is submitted? Even though the form wasn’t native to that page?

Just a quick advice: did you double check if your script have any runtime error and it makes you believe that the trigger isn’t fired?

I had the same trouble weeks ago and when I checked the log I could see my big error!!

I hope it helps.

Saludos

It’s not possible at the moment as far as I aware. I want that option as well, not necessarily home screen but a screen of my choice.

Yeah, it’s amazing that we can’t.