After google form is submitted and the entry is submitted to the spreadsheet, i want to further add a random 10 digit code for the entry. I wrote this script in the script editor:
function onFormSubmit(e) {
var random = Math.floor((Math.random() * 10000000000));
var lock = LockService.getPublicLock();
lock.waitLock(30000);
var sheet = SpreadsheetApp.openById('******************************').getSheetByName('testing (Responses)');
var range = sheet.getRange(sheet.getLastRow(),3);
range.setValue(random);
lock.releaseLock();
}
This works very well when I submit the form. But if I don't use the form for a few hours, and then submit the form, this script executes before the entry is made into the spreadsheet, and hence the random code here replaces the random code of the previous entry. And eventually when the entry is made into the spreadsheet, the cell for this random code is empty. It's weird because this only happens if the form isn't submitted for a few hours, but works perfectly fine if I do it again soon enough.