2

I'm having issue with my script running twice in a Google Form and the linked Sheets. I have one form submit trigger. If I delete this trigger, the script doesn't run at all on a form submit. If I add the trigger back in, it will trigger twice -- but there is only one form submittal in the sheet responses. I thought that maybe I was clicking the form submittal twice, but that doesn't seem to be it. Thanks.

Here is the code:

function myFunction(e) {


  // Set values for event "e" from Response form, each number being a column in the spreadsheet. Column zero is not used - it is the timestamp
  var JobNumber = e.values[1];

  // Create an array from the PNEZD field in the form then find the array location for the inputted shot number
  var PNEZD_field = e.values[2];
  var PNEZD_array = Utilities.parseCsv(PNEZD_field);

  var StructureNumber = e.values[3];

  for (i = 0; i < PNEZD_array.length; i++) {
    if (PNEZD_array[i][0] == StructureNumber) {
      var Elevation = PNEZD_array[i][3];
      var Easting = PNEZD_array[i][2];
      var Northing = PNEZD_array[i][1];
    }
  }


  // STRUCTURE TYPE AND SIZE
  var StructureType = e.values[4];
  var StructureSize = e.values[5];

  // PIPE NUMBER 1  
  var PipeSize1 = e.values[6];
  var PipeMaterial1 = e.values[7];
  var PipeDirection1 = e.values[8];
  var PipeMeasureDown1 = e.values[9];

  // PIPE NUMBER 2 
  var PipeSize2 = e.values[10];
  var PipeMaterial2 = e.values[11];
  var PipeDirection2 = e.values[12];
  var PipeMeasureDown2 = e.values[13];

  // PIPE NUMBER 3  
  var PipeSize3 = e.values[14];
  var PipeMaterial3 = e.values[15];
  var PipeDirection3 = e.values[16];
  var PipeMeasureDown3 = e.values[17];

  // PIPE NUMBER 4 
  var PipeSize4 = e.values[18];
  var PipeMaterial4 = e.values[19];
  var PipeDirection4 = e.values[20];
  var PipeMeasureDown4 = e.values[21];

  // PIPE NUMBER 5 
  var PipeSize5 = e.values[22];
  var PipeMaterial5 = e.values[23];
  var PipeDirection5 = e.values[24];
  var PipeMeasureDown5 = e.values[25];

  //  Calculate Invert Elevations:  
  var Dip1 = Elevation - PipeMeasureDown1;
  var Dip2 = Elevation - PipeMeasureDown2;
  var Dip3 = Elevation - PipeMeasureDown3;
  var Dip4 = Elevation - PipeMeasureDown4;
  var Dip5 = Elevation - PipeMeasureDown5;

  // Build structure information
  var firstLine = StructureType + " " + StructureSize + "\n";
  var secondLine = "Rim=" + Elevation + "\n";
  var thirdLine = PipeSize1 + " " + PipeMaterial1 + " I.E. " + PipeDirection1 + "=" + Dip1 + "'\n";
  var fourthLine = PipeSize2 + " " + PipeMaterial2 + " I.E. " + PipeDirection2 + "=" + Dip2 + "'\n";
  var fifthLine = PipeSize3 + " " + PipeMaterial3 + " I.E. " + PipeDirection3 + "=" + Dip3 + "'\n";
  var sixthLine = PipeSize4 + " " + PipeMaterial4 + " I.E. " + PipeDirection4 + "=" + Dip4 + "'\n";
  var seventhLine = PipeSize5 + " " + PipeMaterial5 + " I.E. " + PipeDirection5 + "=" + Dip5 + "'";

  var Mtext = firstLine + secondLine + thirdLine + fourthLine + fifthLine + sixthLine + seventhLine;

  var calcsheet = SpreadsheetApp.openById('-removed-').getSheetByName('Calculations');
  var ss = SpreadsheetApp.getActiveSpreadsheet(); // ss is now the spreadsheet the script is associated with
  var sheet = ss.getSheets()[1]; // sheets are counted starting from 0
  // sheet is the second worksheet in the spreadsheet
  var cell = sheet.getRange("A1");
  cell.setValue(Mtext);



  // Dump variable to logger log
  //    var dump = "Variable dumps:  first the URL: " + PNEZD_fileURL + " and next the file ID alone: " + PNEZD_fileID + " and now the job number: " + JobNumber;
  //    Logger.log( dump );
  //    Logger.log(JobNumber); 
  //    Logger.log("Data dump: " + PNEZD_field);
  //    Logger.log("Data dump: " + PNEZD_array[3][3]);
  //    Logger.log(StructureNumber + "," + Northing + "," + Easting + "," + Elevation);




}
Scot May
  • 121
  • 10
  • Take a look at [this](https://stackoverflow.com/a/54860085/7215091) – Cooper Mar 15 '19 at 18:13
  • That method resolved the issue? It's strange; I have another script that triggers emails on a form submit, and I haven't run into that issue with that one. Thank you! – Scot May Mar 15 '19 at 18:31
  • Yes. It appears to be a random problem. It will probably get repaired soon. – Cooper Mar 15 '19 at 18:37
  • I tried that out -- it definitely fixed my problem! Thanks again! – Scot May Mar 15 '19 at 19:52
  • I started to observe the very same problem with my Google Forms and a script behind it. The problem started a few days ago (probably some gradual roll-out of some Google bug) – Grzegorz Oledzki May 16 '19 at 07:26
  • I still see double executions in my trigger log. Cooper's code does let the script end cleanly. He has a variation of the code in an answer to a different question of mine here: https://stackoverflow.com/questions/56050749/unknown-status-in-google-app-script-project-executions/56158597#56158597 – Scot May May 16 '19 at 23:23
  • I still have this issue, has it been fixed at all? – Antonio Cucciniello Nov 08 '19 at 19:25
  • I checked my execution transcript just now. I can still see it doubling the number of executions. – Scot May Nov 09 '19 at 20:07

0 Answers0