Search code examples
google-apps-scriptgoogle-sheetsspreadsheetgoogle-formsarray-formulas

Google Appscript VALUE not returned


I'm a complete newbie to programming but wants to learn how. What I did is, I created a google form with 8 questions and the responses goes to a spreadsheet. Now what I want to do is to add another column on the spreadsheet, like a unique ID(should be a sequence like 10001, 10002, 10003, etc.) so I have a unique modifier, in that way once the form is submitted, that unique ID, will also increment by 1.

So far what I did is I created an array on the spreadsheet Unique ID column with this formula: =arrayformula(if(row(A2:A)=1,"Unique ID",if(len(A2:A)>0,9999+row(A2:A),iferror(1/0))))

But, I don't know how to call the value on the google script editor. (example cell: I2 the value is 10001, I3 = 10002). Can you anyone help me with this please? Any help will be appreciated.


Solution

  • Getting your Id from the Form's Linked Sheet

       function onFormSubmit(e) {
          if(e.values && !e.values[1])return;//make question one a required question.  This will keep you from sending emails due to spurious triggers.
          var colnum='enter the column number of you id';//A=1,B=2...
          var id=e.range.getSheet().getRange(e.range.rowStart,colnum).getDisplayValue();
    
        }
    

    Please note: You can not run a function like this from the Script Editor so to avoid the inevitable question I'll simply point out that this requires a trigger to test it. Or you have to figure out a way to provide it with an event object.

    onFormSubmit Event Object