Google-sheets – Add unique QR code field to a spreadsheet based on a form in google docs using Script Trigger

google sheetsgoogle-apps-scriptgoogle-forms

At the end of each row filled in, using a custom Google Form, I'm adding three more columns:

  • Date of creation
  • Unique ID
  • QR code (it is a list of computers)

Unique ID and QR code are unique. QR code is generated from the values of all the cells in the form.

How can I create a script trigger to generate the three cells: Date, Unique ID and QR code onsubmitform?

Here is the code for the cell, for how I simply copy the formulas to generate the QR codes:

Date: =Today()
Unique ID: =CONCATENATE("ROTA-",LEFT("0000",4-LEN(ROW(A2))),ROW(A2)-1)
QR code: =if(isblank(B2), "", image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=Type:"&B2&", "&"Make:"&C2&", "&"HDD:"&D2&", "&"RAM:"&E2&", "&"Drive:"&F2&", "&"Keyboard:"&G2&", "&"Monitor:"&H2&",

The last one is pretty long and each value needs to be adjusted to the next row values.
Basically I need to do something like this but more difficult: reference question

Best Answer

Instead of using a script, consider to add the responses to another sheet using formulas and there add the three columns.

It's worth to say that Today() column will be updated when the recalculation occurs.

I.E. Adding a column with the formula =Today() to the responses of a form add the following formula to A1 in a new sheet:

=ArrayFormula(
{
filter(Sheet1!A:B,Sheet1!A:A<>""),
transpose(
split(
rept(
Today()&char(9),
countif(Sheet1!A:A,"<>")
),
char(9)
)
)
}
)