I use a google docs form to retrieve feedback from our customers. I then download this info into our offline system. Is it possible for google docs to give a unique value to each row it inserts into the spreadsheet as well as the timestamp?

link|improve this question

62% accept rate
AFAIK timestamp is automatically added when you create a Form. When you'd look inside the spreadsheet columns, the first one is usually timestamp (unless you deleted it for some reason and I don't really know what happens if you do that) – Robert Koritnik Feb 23 at 8:38
feedback

2 Answers

up vote 3 down vote accepted

You can do this by adding a script trigger.

Supposing your current Form has two columns Timestamp and the answer to one question. So you currently have columns A and B populating with data. Lets assume you want column C to have you auto increment number.

You need to first go to Tools > Script Editor

In the Script Editor window enter the following script:

function onFormSubmit(e) {

var sheet = SpreadsheetApp.getActiveSheet();
var row =  SpreadsheetApp.getActiveSheet().getLastRow();

sheet.getRange(row,3).setValue(row);


}

Save the script and then go to the Triggers menu and select Current script's triggers

Populate the drop downs as follows:

Google Script Triggers

Click Save

Then Save and close the Google App Script window.

Now when your form is submitted it will populate the row number in column C along with the data that has been submitted via your form.

In you want to change the column that the row number gets saved to you need to change this line of the script:

sheet.getRange(row,3).setValue(row);

and change the value 3 to the corresponding column index number.

link|improve this answer
Is it possible to use this script but I need a unique number so that if I ever delete or add a row it wont screw it up example: I have ID or row 1, 2, 3, 4, 5, 6 but I manualy delete 5 after a form submit ID 6 will shift to line 5 so the next ID on form submit will be 6 again I will have aduplicate. So is it possible to use the time stamp and make a unique auto-incrementing number out of it? – Steve Feb 19 at 20:02
Even better, I now use this to make a get request to a url I control with all the data and put it straight into my app – Toby Allen Mar 16 at 17:24
feedback

Further to the excellent answer by Barry, if you want to be able to remove rows, and still keep a unique ID you can have a static cell that maintains a count. You can then use this number and increment it on every new entry to the table.

So the modification would be to keep a number somewhere on your spreadsheet ('M1' in the code below) and modify the code to look like this:

function onFormSubmit(e) 
{
   var sheet = SpreadsheetApp.getActiveSheet();
   var row =  SpreadsheetApp.getActiveSheet().getLastRow();

   var bugCount = sheet.getRange("M1").getValue();
   bugCount++;

   sheet.getRange(row,1).setValue(bugCount);
   sheet.getRange("M1").setValue(bugCount);
}

Again, change the second last line to change where your ID is placed.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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