I’m creating a custom form and linking it with Google Spreadsheet. After the data from the form is updated into the spreadsheet, then it will run/update the google Calendar, another spreadsheet and finally send email to the form submitter. Now if the submitter submits the form and closes the page while the code is still running, it seems like my code runs twice and causes the data to be duplicated in the spreadsheets too.
My Javascript code :
document.addEventListener('DOMContentLoaded', function(){
document.getElementById("btn").addEventListener("click",runProgram);
},false);
function runProgram() {
//Check Data validation
updateForm();
}
function updateForm(){
google.script.run.executeProgram(dataArray);
}
Here is GAS Code :
function executeProgram(dataArray){
//get Data array and set value in Spreadsheet App
newSubmission();
}
newSubmission function is to run EmailApp, update other sheets and update calendar.
If I remove newSubmission function from executeProgram, the function will only run once, but if I put it back, the function runs twice like the picture below. I’m suspecting my current duration was too long resulting in double execution for the GAS code.
And here is the running time:
With newSubmission function, the execution time to complete is 23 sec. Without newSubmission function, the execution time to complete is 3sec.
Anyone know why it runs twice and how to solve it?