Maximum Date/Timestamp

Thanks, that makes sense. The logic would be:

  1. There will only ever be one (or no) entry per name.
  2. The default action would be REPLACE (all), unless one or more items in the original record are empty.
  3. The latest date/timestamp would be used.

I am a bit focused on another project at the moment, but will have a look at this later, when i have my google sheets "head" :exploding_head: on

Roger, Thank you.

Try this, works for me with this data

The one script handles both REPLACE and UPDATE and should just leave alone if a new entry.

function updateReplace() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('UPDATE');
  var rg = sh.getRange(2,1,sh.getLastRow() -1,6).getValues();
  
  var lastEntry = rg[rg.length-1];
  var prevEntry = ''; 
  for ( var i =0; i<rg.length -1; ++i ) {
    if ( lastEntry[1] == rg[i][1] ) {
      prevEntry = parseInt(i);
      var range = sh.getRange(prevEntry + 2,1,1,6);
      // REPLACE
      if ( rg[prevEntry][3] != "" && rg[prevEntry][4] != "" && rg[prevEntry][5] != "" ) {
        range.setValues([lastEntry]);
        sh.deleteRow(rg.length + 1);
      //UPDATE  
      } else {
        
        if ( rg[prevEntry][3] == "" ) {
        range = sh.getRange(prevEntry + 2,4,1,1);
        range.setValue([lastEntry[3]]);
        range = sh.getRange(prevEntry + 2,1,1,1);
        range.setValue([lastEntry[0]]);
        
      } 
        if ( rg[prevEntry][4] == "" ) {
        range = sh.getRange(prevEntry + 2,5,1,1);
        range.setValue([lastEntry[4]]);
        range = sh.getRange(prevEntry + 2,1,1,1);
        range.setValue([lastEntry[0]]);
        
      } 
        if ( rg[prevEntry][5] == "" ) {
        range = sh.getRange(prevEntry + 2,6,1,1);
        range.setValue([lastEntry[5]]);
        range = sh.getRange(prevEntry + 2,1,1,1);
        range.setValue([lastEntry[0]]);
        
      }
        sh.deleteRow(rg.length + 1);
    } 
    
  }
}
}

Trigger is OnFormSubmit??

Because I copied this script and when data uploaded to sheet, the script gave an error

Error

Script function not found: onFormSubmit

@TIMAI2

Made 2 changes in the script

Working now
So its basically BOTH the functions COMBINED into ONE script !!

It is AMMENDING a value, if existing, and APPENDING a value if NULL

One Query !

Where do I make changes in the script? This sheet was a sample with test data. Actual Sheet has 35 Columns !!!

But Seriously, This Google App Script stuff is Awesome. Need to get to Learn this now.

Thank you for ur effort and time. Will check with live data and revert

I was worried about that :wink:

The script would need rewriting in order to iterate over the the list of columns data in each entry for the appending of values. A nasty, complicated thing! The replace function is not so bad, as we just check if all the columns have an entry.

It may be better to throw the problem back at the user....

Use the fill in form functionality to provide a filled in google form of their last return, and just replace the existing entry (much the same if using an app to complete the entry - return their last entry as response content).

You may also want to consider dropping the use of google forms altogether....

Dropping the use of Google Form ??

Means call Sheet id and Sheet Name from app and define functions in Google App Scripts and call them?

Havent tried it, but its been on my mind for quite a while.
Will give it a shot !

@TIMAI2

I have understood the logic inthis app script u sent.
I tried modifying it to another google sheet with different number of columns , and it worked.
SO I guess, I wud be able to do it for the 35 Column sheet too.

Thank you for ur efforts and time.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.