Delete ligne in google sheet with appinventor

"How can I use a script to delete a row on a Google Sheet using a delete button in App Inventor? The button should search for a name entered in a text box, matching the name in the 7th column of the sheet."
somone help me please;

function doPost(e) {

var nameToDelete = e.parameter.name;

var ss = SpreadsheetApp.openById('1GBmTs_qS2npHSODQWsJwWe8EtYIcENl_VGnG260OhD0'); // Remplacez par l'ID de votre feuille

var sheet = ss.getSheetByName('Feuille 1'); // Remplacez par le nom de votre feuille

var dataRange = sheet.getDataRange();

var values = dataRange.getValues();

for (var i = values.length - 1; i >= 0; i--) {

var name = values[i][6]; // 7ème colonne (indice basé sur 0)

if (name === nameToDelete) {

  sheet.deleteRow(i + 1); // L'indice de ligne est basé sur 1

  return ContentService.createTextOutput('Ligne supprimée avec succès');

}

}

return ContentService.createTextOutput('Nom non trouvé dans la feuille');

}

Show your relevant blocks.

Has your script been correctly deployed?

1 Like

"How can I use a script to delete a row on a Google Sheet using a delete button in App Inventor? The button should search for a name entered in a text box, matching the name in the 7th column of the sheet."
somone help me please;
her is my blocs and script

function doPost(e) {

var nameToDelete = e.parameter.name;

var ss = SpreadsheetApp.openById('1GBmTs_qS2npHSODQWsJwWe8EtYIcENl_VGnG260OhD0'); // Remplacez par l'ID de votre feuille

var sheet = ss.getSheetByName('Feuille 1'); // Remplacez par le nom de votre feuille

var dataRange = sheet.getDataRange();

var values = dataRange.getValues();

for (var i = values.length - 1; i >= 0; i--) {

var name = values[i][6]; // 7ème colonne (indice basé sur 0)

if (name === nameToDelete) {

  sheet.deleteRow(i + 1); // L'indice de ligne est basé sur 1

  return ContentService.createTextOutput('Ligne supprimée avec succès');

}

}

return ContentService.createTextOutput('Nom non trouvé dans la feuille');

}

Please show your full URL as text. Should you have a ? instead of an & before name ?

https://script.google.com/macros/s/AKfycbxwBPSx6t6ARGftkiuHh1Ii5IzktHmo0Ds6kVJvEHUcRSu1reVvwN0ZJq6MOQOkc1ez/exec

URL About google sheet:
"https://docs.google.com/spreadsheets/d/1GBmTs_qS2npHSODQWsJwWe8EtYIcENl_VGnG260OhD0/edit#gid=0

Also, you have dopost in your script but you are making a get request.

Change doPost to doGet and redeploy your script as a new version

can you help me more

These blocks

This script

function doGet(e) {

var nameToDelete = e.parameter.name;

var ss = SpreadsheetApp.openById('1GBmTs_qS2npHSODQWsJwWe8EtYIcENl_VGnG260OhD0'); // Remplacez par l'ID de votre feuille
var sh = ss.getSheetByName('Feuille 1'); // Remplacez par le nom de votre feuille
var dataRange = sh.getDataRange();
var values = dataRange.getValues();
  for (var i = values.length - 1; i >= 0; i--) {
    var delVal = values[i][6]; // 7ème colonne (indice basé sur 0)
    if (delVal == nameToDelete) {
     sh.deleteRow(i + 1); // L'indice de ligne est basé sur 1
     return ContentService.createTextOutput('Ligne supprimée avec succès');
    }
  }

return ContentService.createTextOutput('Nom non trouvé dans la feuille');

}

Should be working. Check your Feuille 1 - is there are space between Feuille and 1 ?

he doesn't work

What doesn't work ?

Show your sheet, blocks, script and any outputs.


script:

function doGet(e) {

var nameToDelete = e.parameter.name;

var ss = SpreadsheetApp.openById('1GBmTs_qS2npHSODQWsJwWe8EtYIcENl_VGnG260OhD0'); // Remplacez par l'ID de votre feuille

var sh = ss.getSheetByName('doc'); // Remplacez par le nom de votre feuille

var dataRange = sh.getDataRange();

var values = dataRange.getValues();

  for (var i = values.length - 1; i >= 0; i--) {

    var delVal = values[i][6]; // 7ème colonne (indice basé sur 0)

    if (delVal == nameToDelete) {

     sh.deleteRow(i + 1); // L'indice de ligne est basé sur 1

     return ContentService.createTextOutput('Ligne supprimée avec succès');

    }

  }

return ContentService.createTextOutput('Nom non trouvé dans la feuille');

}

What do you see in the responseContent ?

nothing
just somthing lik html head link ......

Then it is "something" !!

Capture the responsContent to a label, copy the complete content of the label and post it back here as text. The reason is usually at the end of the text/html

[edit] - OK you have done that.

The script is not finding the sheet named 'doc'

Have you re-deployed your script to a new version?


my app

bod nech amolay
it doesn't work it make same problem

Hmmm

Check you script again for any errors

I am running the same script / blocks / sheet, and it works OK

ok thank you so much