Google Forms - I have set up a google form and I want to assign a unique id each of the completed incoming form inputs. My intention is to use the unique ID as an input for another google form I have created which I will use to link the two completed forms. Is there another easier way to do this?

I'm not a programmer but I have programming resources available to me if needed.

3

Best Answer


I was also banging my head at this and finally found a solution.

I compose a 6-digit number that gets generated automatically for every row and is composed of:

  • 3 digits of the row number - that gives the uniqueness (you can use more if you expect more than 998 responses), concatenated with

  • 3 digits of the timestamp converted to a number - that prevents guessing the number

Follow these instructions:

  1. Create an additional column in the spreadsheet linked to your form, let's call it: "unique ID"
  2. Row number 1 should be populated with column titles automatically
  3. In row number 2, under column "Unique ID", add the following formula:

    =arrayformula( if( len(A2:A), "" & text(row(A2:A) - row(A2) + 2, "000") & RIGHT(VALUE(A2:A), 3), iferror(1/0) ) )

    Note: An array formula applies automatically to the entire column.

  4. Make sure you never delete that row, even if you clear up all the results from the form
  5. Once a new submission is populated, its "Unique ID" will appear automatically

Formula explanation:

  • Column A should normally hold the timestamp. If the timestamp is not empty, then this gives the row number: row(A2:A) - row(A2) + 2
  • Using text I trim it to a 3-digit number.
  • Then I concatenate it with the timestamp converted to a number using VALUE and trim it to the three right-most digits using RIGHT

Voila! A number that is both unique and hard-to-guess (as the submitter has no access to the timestamp).

If you would like more confidence, obviously you could use more digits for each of the parts.

You can apply unique ID numbers using an arrayformula next to the form data. In row 1 of the first rightmost empty column you can use something like

=arrayformula(if(row(A1:A)=1,"UNIQUE ID",if(len(A1:A)>0,98+row(A1:A),iferror(1/0))).

A few comments regarding the explanation provided by @Ying, which I will try to expand, as it is very good.

> Column A should normally hold the timestamp. 

In my case, it is date+time stamp.

enter image description here


> 4. Make sure you never delete that row, even if you clear up all the results from the form

That issue can easily be avoided by placing the formula in the header like this

={"calculated_id";arrayformula( if( len(C2:C); "" & text(row(C2:C) - row(C2) + 2; "000") & RIGHT(VALUE(C2:C); 3); iferror(1/0) ) )}

This formula provides an string for one cell, and a formula for the next one, which happens to be an array formula which will cover all the cells below.

enter image description here

Note: Depending on your language settings you may need to use ";" or "," as separator among parameters.


> 5. Once a new submission is populated, its "Unique ID" will appear automatically

Issue

And here is the issue I see with this solution.If the Google Form allows responders to Edit their responses, the date+time stamp will change and so the calculated_id.

A workaround is to have 2 columns, one is the calculated_id and the other will be static_id.

static_id will take whatever is on calculated_id only if itself has no data, otherwise it will stay as it is.

Doing that we will have an ID that will not change no matter how many updates the response experience.

The sort formula for static_id is

=IF(AND(IFERROR(K2)<>0;K2<>"");K2;L2)

The large one is

={"static_id";ArrayFormula(IF(AND(IFERROR(M2:M)<>0;M2:M<>"");M2:M;L2:L))}

M or K -> static_id

L -> calculated_id

Remember to put this last one on the header of the column. I tend to change the color to purple when it has a formula behind, so I don't mess with it by mistake.

enter image description here


Extra info.

The numeric value from the date/time stamp differs when it comes from both or just one. Here are some examples.

enter image description here

Note that the number of digits on the fractional part differ quite a lot depending on the case.