"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');
}
TIMAI2
August 20, 2023, 8:37am
2
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');
}
TIMAI2
August 20, 2023, 8:56am
4
Please show your full URL as text. Should you have a ?
instead of an &
before name ?
TIMAI2
August 20, 2023, 9:13am
6
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
TIMAI2
August 20, 2023, 11:42am
8
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
?
TIMAI2
August 21, 2023, 9:39am
10
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');
}
TIMAI2
August 21, 2023, 10:09am
12
What do you see in the responseContent ?
nothing
just somthing lik html head link ......
TIMAI2
August 21, 2023, 10:23am
14
eps_info-sport:
nothing
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.
TIMAI2
August 21, 2023, 10:29am
15
The script is not finding the sheet named 'doc'
Have you re-deployed your script to a new version?
The new google script editor works in a different way when you update/change the content of your script. If you make a new deployment, then it creates a new script url. We do not want this for our apps, we want the script url to stay the same! In...
bod nech amolay
it doesn't work it make same problem
TIMAI2
August 21, 2023, 10:56am
18
Hmmm
Check you script again for any errors
I am running the same script / blocks / sheet, and it works OK