Update Row By Column Value

Hello, I want to update the values of a row in a Google Sheets spreadsheet based on a specific value located in the 7th column on Google Sheets. I've used the following script, but after execution, it displays the response "Update successful" while nothing gets updated. Can you please assist me? Thank you.

my script:

function updateRowByColumnValue(e) {

  var ss = SpreadsheetApp.openById('1mgWiNwNhKfI64ZWOvaGPKIgxC6jiQ620tjH7-27V3bQ');

  var sh = ss.getSheetByName('cross');

  var columnNumber = 7;

  var gValue = e.parameter.G;

  var lr = sh.getLastRow();

  for (var row = 1; row <= lr; row++) {

    var data = sh.getRange(row, columnNumber).getValue();

    if (data == gValue) {

      var b = e.parameter.B;

      var c = e.parameter.C;

      var d = e.parameter.D;

      var eValue = e.parameter.E;

      var fValue = e.parameter.F;

      var hValue = e.parameter.H;

      sh.getRange(row, 2).setValue(b);

      sh.getRange(row, 3).setValue(c);

      sh.getRange(row, 4).setValue(d);

      sh.getRange(row, 5).setValue(eValue);

      sh.getRange(row, 6).setValue(fValue);

      sh.getRange(row, columnNumber).setValue(gValue);

      sh.getRange(row, 8).setValue(hValue);

      Logger.log('Ligne mise à jour avec succès');

      return ContentService.createTextOutput('Mise à jour effectuée avec succès');

    }

  }

  Logger.log('Aucune ligne correspondante trouvée');

  return ContentService.createTextOutput('Aucune ligne correspondante trouvée');

}

// Exécutez la fonction lorsque la requête provient d'App Inventor avec func=UPDATE

function doGet(e) {

  if (e.parameter.func === 'UPDATE') {

    return updateRowByColumnValue(e);

  } else {

    return ContentService.createTextOutput('Fonction non valide');

  }

}

You could try like this:

image

function doPost(e) {
  var ss = SpreadsheetApp.openById('1An2qqq2nf6X8epceYN2ffjQON299h_L2WddjZ9pT_KY');
  var sh = ss.getSheetByName('Sheet1');
  var data = JSON.parse(e.postData.contents);
  var col7 = data[5];
  var rng = sh.getDataRange();
  var vals = rng.getValues();

try {
  for (var i = 0; i<vals.length; i++) {
    if (vals[i][6] == col7) {
        sh.getRange("B" + (i+1) + ":H" + (i+1)).setValues([data]);
    }
  }
  return ContentService.createTextOutput('Update Successful'); 
} catch {
    return ContentService.createTextOutput('Something went wrong');
}
}

Before:

After:

thank you

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