I have multiple Google Forms that 'On Form Submit' trigger Apps Script to insert the new row of data into a centralized database (Google Sheet).
Example: On Form Submit, Google Form 1 takes the last row of data submitted and pushes this new row of data to a Google Sheet titled 'All Form Data'. Similarly, on Form Submit Google Form 2 takes the last row of data submitted and pushes this new row of data to the same 'All Form Data' spreadsheet.
The Apps Scripts in Google Form 1 and Google Form 2 search the 'All Form Data' Spreadsheet for the last row of data and insert the new row of data into the next row using a script similar to this where 'data' is an array of the values:
allformdata.getRange(allformdata.getLastRow() + 1, 1, 1, 10).setValues(data)
The issue with this approach is that if Google Form 1 and Google Form 2 are submitted at relatively the same time, both Apps Scripts start running and identify the last row of the 'All Form Data' Spreadsheet. If the last row is 100, they will both insert the new row of data into row 101. Whichever script finishes last will be the form's data that appears in row 101. This means that I am missing data that was sent from one of the Google Forms.
What method would be most appropriate to make sure that data from multiple different Google Forms gets added to a centralized Google Sheet database without risking the data not being added to the database?
You help is appreciated in advance!
David