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()
}
}
}
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
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()
}
}
}
}
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()
}
}
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.
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?