Google-sheets – How to implement a script that creates a unique ID for a Google form submission

google sheetsgoogle-apps-scriptgoogle-forms

I need to create a unique ID upon submission of a form which will be used as a project number for tracking. The number needs to be unique but not based on rows or other changeable data because completed projects are kicked to an archive sheet where they will be on a different row and therefore will change both that project's number and the number of all other projects below it on the spreadsheet.

I found the answer to Can I add an autoincrement field to a Google Spreadsheet based on a Google Form?, but the script is giving me errors, so maybe I need some advice on making it work.

I'm a very beginner user with no script writing experience but I cannot find a formula that doesn't rely on rows or otherwise would retain a number throughout different sheets. Any help is appreciated!

Best Answer

The problem is in the first line of the script. Your form ID is the special ID that identifies the form. You can see it in the address of the form (it's the bit in bold)

docs.google.com/forms/d/17rxZ5vzy0OcxibXV6aRpso7Xm_Vs0FpxMLgbchjO998/viewform.

You accidentally used the form name instead.

That being said, I should have just used the Spreadsheet.getFormUrl() in the original answer. I'll change that now, then you won't have to worry about the ID at all.