3

I'm trying to create an auto-generated unique ID# for each meetings being submitted via a Google Form.

The unique ID# solution must also meet the following requirements.

  • The ID# must be static (not tied to row number).
  • I need to be able to set a starting point other than "1" for the unique ID#'s.

I've tried the following solution, but it created ID#'s based on row # and if a row is removed, it duplicates a unique ID#.

Can I add an autoincrement field to a Google Spreadsheet based on a Google Form?

3

This can be done with the following script: set a trigger "on form submit" for this function.

The customizable parameters are: the column number where to insert Id, and the initial Id. The function uses Script Properties to keep track of the used Id, so they will not be repeated.

function generateId(e) {
  var columnNumber = 5;
  var initialId = 42;
  var sp = PropertiesService.getScriptProperties();
  var id = sp.getProperty("Event Id") || initialId;
  e.range.offset(0, columnNumber - 1, 1, 1).setValue(id);
  sp.setProperty("Event Id", id + 1);
}
  • Bookend, Thanks for helping with this. I've tested the script and I receive the following error. TypeError: Cannot read property "range" from undefined. (line 6, file "Code"). I have not edited your code at all, just copy/paste into script editor. Ideas? Thanks again. – Mr. B Jul 19 '16 at 2:08
  • 1
    The function is meant to be run by a trigger, not manually. – user79865 Jul 19 '16 at 2:09
  • Got it. It works with the trigger. Thanks again for your help! – Mr. B Jul 19 '16 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.