Here’s a tip on creating unique ID’s directly in Google sheets with Apps script:
The code works by scanning your sheet for edits in rows. If the edited row doesn’t have a ID in a set column (aka empty), it creates one.
This code does not add unique ID’s to empty rows, or change the unique ID if the row is edited.
Note that the unique ID doesn’t go away if you delete all other information in a row.
-
Open your sheet and add a column with a header name with for example “ID”
-
Go to Tools → Script Editor and give your new script a name.
-
Paste the code and change the following values:
– var SHEETNAME = “Your sheet”; (Change this to the name of the sheet which you are going to use)
– var ID_COLUMN = 1; (Change it to the number corresponding to your column letter where the header is “ID” or whatever you called it)
– var ID_LENGTH = 5; (Change this to 8 to be consistent with Appsheet’s recommendation) -
Save your project
-
Then click

-
Click add trigger
-
Then choose the settings below
Code is here:
EDIT:
Change these parts (the function) to get a letter first in the UniqueID:
function generateUID () {> var ALPHABET = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;> var ALPHABET2 = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’;> var rtn = ‘’;> rtn += ALPHABET2.charAt(Math.floor(Math.random() * ALPHABET2.length));> for (var i = 0; i < ID_LENGTH; i++) {> rtn += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));> }> return rtn;> }
