Delete the listview selection from googlesheet

what is wrong with my block to delete the listview selection as its deleting sometimes all and sometimes the first row not the specific one?

image

and here is the delete script
//DELETE SINGLE RECORD
else if (e.parameter.func == "Delete") {
var record = e.parameter.id;
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
sh.deleteRow(parseInt(record) + 1);
return ContentService.createTextOutput("Success");

If your variable global url_inside is just the apps script url, then your blocks should read
?id=Listview.selectionindex&func=Delete

When running a Web GET url for apps script, your first parameter should be preceeded by a ?, any following parameters with an &

so what is the solution to delete the specific selected from the listview selection?

After the script url you should use? (Question mark) and not &

So the format should be

web url to getGlobalScript url?id=Listview selection index&func=Delete

In your case it seems,

web url to getGlobalScript url&id=Listview selection index&func=Delete

This is what @TIMAI2 pointing

Your final url must be in this format to meet your requirement. Just use do it on the web url after it trigger to verify the Get request

https://script.google.com/macros/s/your-script-id/exec?func=Delete&id=5

Or

https://script.google.com/macros/s/your-script-id/exec?id=Num&func=Delete

@TIMAI2 @Spicy_Topics
i used that method so if you have a better method lets share it with me

image

image

Why are you sending a spreadsheetID and a sheetName, if your script is getting the activeSpreadsheet and the first sheet ?

Do you mean to delete the supplied id PLUS 1 ?

i just took it from a project but if i can exclude spreadsheetID and a sheetName it will be better as its already the first sheet and all i want to delete the selected row

I can't see anything wrong with your script.

if you dont mind, pls check this web url after it get triggers .. and share with us hiding your sheet id,the script id

@TIMAI2 @Spicy_Topics

i tried that script but still deleting the first row and i need to delete the selected listview selectionindex one

https://script.google.com/macros/s/your-script-id/exec?id=Num&func=Delete
and that one as well
https://script.google.com/macros/s/your-script-id/exec?func=Delete&id=5

Why don't you try AIA here for your need, may be you'll get the solution [PAID] Ultimate Google Spreadsheet Extension Pack With/Without Image Hosting (An Alternative To Airtable) - Extensions - MIT App Inventor Community

Thanks, Alright let me check it

1 Like

i cant check a paid file until knowing that what i need
as i just wanna delete the selected listview selection not the first row

AIA file is free for checking, you can check all the functions of the extension and can purchase only after completely satisfied. I have developed this extension for ease of everyone, so that nobody has to face difficulty wit spreadsheet's read write operations with apps script.

using the above blocks, i have tested the code and found working fine also it deletes exactly what i am deleting.. and find no issue with the code..

image
Testing.aia (75.5 KB)

@TIMAI2 script code only i have used..

1 Like

@Spicy_Topics alright will check thanks so much, can you send me your read and delete scripts codes as a text then ?

I will have another go too, keeping things as simple as possible

Sheet1 of Spreadsheet

image

Script

function doGet(e) {
  if ( e.parameter.func == "deleteRow" ) {
  var ss = SpreadsheetApp.openById(e.parameter.sheetID);
  var sh = ss.getSheetByName(e.parameter.gridName);
  sh.deleteRow(parseInt(e.parameter.row));
  return ContentService.createTextOutput('Row ' + e.parameter.row + ' Deleted');
}
}

Blocks

image
(note the textbox is multiplied by 1 to make it a number - not essential, but could help in some circumstances if you forget to use "parseInt" in your script)

Screen Before

image

Screen After

image

Spreadsheet After

image

You see that row 4 of the spreadsheet that contained [3,Bob] has been deleted.
Note: you now have a new row 4 [4,Nick]. (maybe this is your issue, that you are attempting to delete a specific record and not a row?)

i tried it but dunno wny isnt working maybe its not identifying the listview selectionindex as a row

image
image

so how can i say delete the listview selection, i didnt mean to delete a row number?

i have used the same code used in this site, i always suggest the same cide to one all. That was easy to connect app to gsheet. Credit to @TIMAI2 only.

You mean particular cell? Only the selected cell instead of complete row??

By the way do you get above such error on selecting an item in listview? If so how did you set values into the liatview? Show us your Complete code regarding this to help you better

Once you delete as i did in the eg pls refresh your list view