Home > Mobile >  how can i get the last modified row in a sheet to display a value in a form response from another sh
how can i get the last modified row in a sheet to display a value in a form response from another sh

Time:10-30

I have a sheet named "Credentials" populated with the following data:

enter image description here

And another sheet in the same spreadsheet named "Clients" which is linked to a google form:

enter image description here

My goal here is to show on the confirmation message the data from the "Credentials" sheet which is in the same row as the row that is filled when a form is submitted. E.G: the form data that was stored in row 2 should show "usr a" and "pass a" on the confirmation message

I have this apps script to do so but it always shows the last data from the "Credentials" sheet on the form confirmation message and i can't see why:

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet_clientes = ss.getSheetByName('Clients')
  var sheet_demos = ss.getSheetByName('Credentials')
  var form = FormApp.openByUrl(ss.getFormUrl())

  
  var demosRange = sheet_demos.getRange('A2:B4')
  var demosData = demosRange.getValues()
  var lr = sheet_clientes.getLastRow()
  var user = demosData[lr][0]
  var password = demosData[lr][1]
  form.setConfirmationMessage('Congratulations: Your user is:\n'   user   '\n Your password is:\n'   password)
}

CodePudding user response:

You can use the enter image description here

Example:

enter image description here

enter image description here

References:

  • Related