Appending initial timestamp from Google Form to end of record in order to permanently store create date onFormSubmit
<p>I need to be able to store (by appending to the record) the create date of google form responses where the initial timestamp does not get overwritten when the form is edited. This form is Hosted on Google and is within a Google Apps for Business environment.  </p>

<p>This information exists but at some point but gets dumped on form update. It seems like this would have a wide application to people using Google Forms that are edited after their creation for analytical purposes. </p>

<p>This <a href="https://productforums.google.com/forum/#!topic/docs/M_WuHrjcDow" rel="nofollow">Google Docs Forum</a> explains a situation quite similar to mine but didn't include the code they used.  </p>

<p>I have dug through the google developer site and determined that the best way I should implement this function would be to use a onFormSubmit trigger on the response spreadsheet rather than the form itself since the field I want to reference (Timestamp) isn't selectable until written to the google sheet and because I want to store the result in a new column in the spreadsheet anyway. </p>

<p>I tried referencing <a href="https://productforums.google.com/d/msg/docs/T9BHurb7CbE/RE1Z9-Ywo6MJ" rel="nofollow">this solution</a> and modifying for my purpose as it was the closest code snippet which I found to the problem I am trying to solve. </p>

<p>Below is my commented code. Although, there are things I still need to address such as my if else and my hardcoding the createDateColumn, I was able to get this to run without these (using run menu in Google App Script linked to spreadsheet) but the cell it should be writing the timestamp to for some reason now has a value of "Range" after the script was executed so I assume I am setting the value incorrectly. </p>

<p>I also tried adding a new entry into the form however, the onFormSubmit didn't execute on its own so there may be other unaddressed issues as well.</p>

<p>Any help is appreciated. My coding skills are a little rusty.</p>

<pre><code>    function onFormSubmit(e) 
{
  var ss = SpreadsheetApp.getActiveSheet();

  var lastRowInx = ss.getLastRow(); // Get the row number of the last row with content
  var createDateColumn = 50; //CreateDateColumn is currently in AX (Column 50) Possibly find named range since hardcoded isn't ideal. LastColumn doesn't work because some responses not required

//  if () condition should be ss.getRange(lastRowInx, createDateColumn) == ""; so that subsequent edits to Google Form which trigger timestamp updates don't overwrite original create date
  //{
    var timestamp = ss.getRange(lastRowInx, 1); // Get timestamp entry
    var createDate = ss.getRange(lastRowInx, createDateColumn);
    createDate.setValue(timestamp);
  //}
  //else {} //should be do nothing
}
</code></pre>

<p>****UPDATE****
It works! Thanks for your help @Sandy.</p>

<p>To fix my other issues I mentioned previously, I also modularized the code as I am doing a few other tasks onFormSubmit and I wanted to be able to use the createDate in another function. Note: I have removed the other functions from the code snippet as they don't apply to the question.  </p>

<p>I also used getMaxColumns() instead of hardcoding the column number. </p>

<p>Here is the updated code for future user's use</p>

<pre><code>function onFormSubmit(e) 
{
 var ss = SpreadsheetApp.getActiveSheet();
 var lastRowInx = ss.getLastRow(); // Get the row number of the last row with content
 var createDateColumn = ss.getMaxColumns(); //CreateDateColumn is currently in AX (Column 50) which is the last/max column position

  var createDate = setCreateDate(ss, lastRowInx, createDateColumn);
}//This is the end of onFormSubmit
function setCreateDate(ss, lastRowInx,createDateColumn) // Stores the create date timestamp in Column AV on the backend
{
  if (ss.getRange(lastRowInx, createDateColumn).getValue() == "") // so that subsequent edits to Google Form which trigger timestamp updates don't overwrite original create date
  {
    var timestamp = ss.getRange(lastRowInx, 1).getValue(); // Get timestamp entry which is currently in A (Column 1)
    var setDate = ss.getRange(lastRowInx, createDateColumn);
    var createDate = new Date(timestamp);
    setDate.setValue(createDate).setNumberFormat("MM/dd/yyyy hh:mm:ss");
  }
  else {} //should do nothing
  return createDate;
}//This is the end of setCreateDate function
</code></pre>