In such case @mustafaalbasel already unknowgly you have deployed that code too in your script and you should follow certain few more logics as below. Also we do not know which col you have added in your listview.. Suppose if you have added col A then in REF place pls use Join {A+listviewselectionIndex}, depending upon the imported item in the listview pls choose the col name and let be the ROW as your listview selction index.. now the final url; must belook like this..
If you want to delete by record (using the ID), then your script could be like so:
function doGet(e) {
if ( e.parameter.func == "deleteRow" ) {
var ss = SpreadsheetApp.openById(e.parameter.sheetID);
var sh = ss.getSheetByName(e.parameter.gridName);
var lr = sh.getLastRow();
var ids = sh.getRange('A2:A'+lr).getValues();
var idIndex = ids.flat().indexOf(parseInt(e.parameter.id));
sh.deleteRow(parseInt(idIndex)+2);
return ContentService.createTextOutput('Record ID: ' + e.parameter.id + ' Deleted');
}
}
Before
After
Screen
Blocks
Remember to parseInt() the id parameter, otherwise you will see either a fail, or the first row deleted. You will see that even though I convert the textbox1.text to a number, Web1.Get still sends it as a string.
Note, I use the indexOf() function which returns an index from a base of 0.
@Spicy_Topics@TIMAI2
Maybe its my fault that i didnt understand your ideas, let me show you
this is a sample from my project i made it for you to check it hoping to understand what am doing skip the first page just click on listview button above
so all i want when selecting the element from the listview2 and press send so it should delete the exact row as it was deleting the first row so lets check the file hoping to fix what it needs to adjust it to my project
skip any other errors than am requesting as i copied it from my project
Now your query is perfect, in such case try this code..
else if (fn == 'deleteRow1') {
var dataArray;
try {
dataArray = JSON.parse(e.parameter.dataArray); // Use 'dataArray' as per your request
} catch (error) {
return ContentService.createTextOutput('Invalid JSON: ' + error.message);
}
return deleteRow(dataArray, sh);
}
}
function deleteRow(dataArray, sheet) {
var values = sheet.getDataRange().getValues();
var toDelete = dataArray[0]; // Extract the first (and in this case only) row for matching
for (var i = values.length - 1; i >= 0; i--) {
var currentRow = values[i];
// Compare each cell in the row with the corresponding cell in toDelete
if (currentRow.length === toDelete.length && currentRow.every((cell, index) => cell === toDelete[index])) {
sheet.deleteRow(i + 1); // Delete the matched row, accounting for 1-indexed rows
return ContentService.createTextOutput('Row deleted successfully.');
}
}
return ContentService.createTextOutput('No matching row found.');
}
and it deleted successfully.. if you wanna test copy the url and change with anyother value as given in the below sheet.
before
After
Paste the above code.
Prepare list view
On selection, prepare proper list then make final url as shown above..
Now i adjusted value in gsheet like this
so it returns the below response.
Version -II
i have used these code to return which matching row was delted along with the success response. (deletes exact matching row data)
function deleteRow(dataArray, sheet) {
var values = sheet.getDataRange().getValues();
var toDelete = dataArray[0]; // Extract the first (and in this case only) row for matching
for (var i = values.length - 1; i >= 0; i--) {
var currentRow = values[i];
// Compare each cell in the row with the corresponding cell in toDelete
if (currentRow.length === toDelete.length && currentRow.every((cell, index) => cell === toDelete[index])) {
var rowDeleted = i + 1; // Row number is 1-indexed
sheet.deleteRow(i + 1); // Delete the matched row
return ContentService.createTextOutput('Row ' + rowDeleted + ' deleted successfully.');
}
}
return ContentService.createTextOutput('No matching row found.');
}
Above code returns the following oputput once it finds exact matching details
i didnt work with me
i just added the script code in the file, lets just try my aia file below
i guess it will be better if there is a code so it will be like if the colums b, c,d , so on are matched with the listview selection
lets look at my file please maybe it has another concept, just see the label i added for showing the listview2 elements
here is the aia file just take a quick look at it Sampleproject.aia (5.2 MB)
its sending the exact data successfully to another sheet but i wasn't deleting the exact row but now the new script isn't working with me
the second screen just press on the listview button
the delete script is the only one worked with me
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");
}
but as you know its not deleting the selected one
@mustafaalbasel As i said already you should send to the apps script woith the same data as it showing in the gsheet. But you use query formula to filter the result and want to delete the matching data with gsheet. It is neever possible.
For this kind of confusion you should choose delte the row by index method as suggested earlier.
pls delete the data by listview index method alone as suggested by @TIMAI2
@Spicy_Topics the query is in the listview1 but the listview2 has all data no query which am deleting from and it worked as i said above but didnt work with the exact one
Pls understand the logic, in gsheet all datas are there. But you are specifically taking the data want to delete it.How is it possible by index method?
the solution is, Do not use query. Call the data then set in the list view in the same order. Now if you delete it by index method it will work..
Eg. In ghseet 10 datas are there. Using query you are calling two datas. Now how is it possible to delete the data by index method? if you delete the data in gsheet then order will be changed in the gsheet. Also you are changin the order in the listview , so matching option also become useless in your code.
May be due to your language i get confsuded. can you make it more understandable the blocks? many web are there, list view are there. Pls remove others from ths sample aia and give exactly the required url listview alone so that we can assist you easily. also share with us currently what script you are using in the apps script to help you better
@Spicy_Topics let me show you my app concept
they are orders being added by customers so am arranging them by numbers of people by the query in the listview1 and when pressing on the listview1 its showing the listview2 with all orders for each commutative num of people
list view 1 num of people 5 data.....
list view 2 mustafa 3 data....
james 2 data.....
so i should when pressing on the listview2 and pressing send it should delete from the google sheet depending on the data selected from the listview 2
I understand your problem now more clearly after seeing your blocks slowly one by one.
Enable the ShowlistAsjson from teh project propertise
Since we are sending col B to col K data only to gsheet to find the matching data to be deleted, i am modifying the script code to look in from Col B to col K then delete it. Here is the revised code. Now paste these code , deploy it, take teh script url, change the project settings, paste teh url and try to delete.
function deleteRow(dataArray, sheet) {
var values = sheet.getDataRange().getValues();
var toDelete = dataArray[0]; // Extract the first (and in this case only) row for matching
// Create a slice of 'toDelete' from column B (index 1) to column K (index 10)
var toDeleteSlice = toDelete.slice(1, 11); // This gets elements from index 1 to 10 (B to K)
for (var i = values.length - 1; i >= 0; i--) {
var currentRow = values[i];
// Create a slice of 'currentRow' from column B (index 1) to column K (index 10)
var currentRowSlice = currentRow.slice(1, 11); // This gets elements from index 1 to 10 (B to K)
// Compare only the specific slices from column B to column K
if (currentRowSlice.length === toDeleteSlice.length && currentRowSlice.every((cell, index) => cell === toDeleteSlice[index])) {
sheet.deleteRow(i + 1); // Delete the matched row, accounting for 1-indexed rows
return ContentService.createTextOutput('Row deleted successfully.');
}
}
return ContentService.createTextOutput('No matching row found.');
}
the most difficult part is your language. During screen initialize you are using many weband i amunable to read all teh web get requests. morever one of your web get query throws that csv table text to row error gives me. now i will give you plain eample in new screen by calling your gshet and deleting it.. pls wait
Sorry dear.. I tried myself with your sheet. i did copy of your sheet and made adjustement with the apps script. Called all data and deleted it by the id and it works fine. no issue. It is deleteing exactly the same what i targeted. Pls test this aia (sheet2), and ghseet.