Delete the listview selection from googlesheet

@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.

Got it now ? @mustafaalbasel

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

Once it was deleted then again recall the listview through web get request to avoid misunderstanding between app amd gsheet

@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.

  1. Enable the ShowlistAsjson from teh project propertise
  2. 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.');
}

image

And in blocks side make adjustment like this

If you adjust all the above then i am sure it will work

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

1 Like

will translate all blocks to English and send you the file again

@Spicy_Topics i just transferred all blocks to english, lets check it now
Sampleproject (3).aia (5.2 MB)

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.

Sample_Jai.aia (3.1 MB)

Gsheet Link

@Spicy_Topics Thanks so much, finally it works now

one last thing please
lets check the comment i just mentioned you in

1 Like

i noticed that it is deleting by English not Arabic id, maybe it was the main issue i didn't notice before
so when selection an arabic name its deleting the first or lasr row, while deleting english name then it is deleting the exact one

1 Like

@Spicy_Topics
the script code you created is working well with the sheet i sent you before but when i added the same script code to another sheet it didnt work for each read or delete, so how can i fix that please?

function doGet(e) {
  return ManageSheet(e);
}

function doPost(e) {
  return ManageSheet(e);
}

function ManageSheet(e) {
  // READ ALL RECORDS
  if (e.parameter.func === "ReadAll") {
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheets()[0];
    var rg = sh.getDataRange().getValues();
    var outString = '';
    
    for (var row = 0; row < rg.length; ++row) {
      outString += rg[row].join(',') + '\n';
    }
    
    return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);
  }
  
  // DELETE SINGLE RECORD BASED ON REFERENCE ID (Column A)
  else if (e.parameter.func == "delete") {
    var referenceID = e.parameter.id;  // This is the Reference ID passed from the app
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheets()[0];
    var data = sh.getDataRange().getValues();  // Get all data in the sheet

    // Search for the row that matches the reference ID in Column A
    for (var row = 0; row < data.length; ++row) {
      if (data[row][0] == referenceID) {  // Assuming Reference ID is in Column A (index 0)
        sh.deleteRow(row + 1);  // Delete the row (row + 1 because Google Sheets rows are 1-indexed)
        return ContentService.createTextOutput("Success");
      }
    }
    
    // If no match is found
    return ContentService.createTextOutput("Reference ID not found");
  }
}


//https://script.google.com/macros/s/AKfycbxkA2EzwHPfYqO-tU3YhlStJZ0hCQP-EPQKENIiD1zoPNfQ2TVRd51hdFf4htzvfr9Q0A/exec

Have you deployed it there by anyone can access? Did you use sheet id correctly? No way for not working unless we commit mistake. Each param must be case sensitive. If anyone is misspelled then it will not work dear

the provided code in both the sheets will delete the exact row if it finds matching col A value and not by row number method..

 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");

this code only will deletes the row based on rowNumber

@Spicy_Topics Yes i know so did you try to delete from the second sheet and it deleted or got an error?

both the sheet we cannot delete because in col A data is in arabic so it will be mis read. In both the seheet i got Ref ID is not found only if i run script url with delete function

@Spicy_Topics
its deleting well in the first sheet you adjusted but it doesn't work in the second sheet

@Spicy_Topics this is the sheet1 with deletion


after deleting 14

Pls check in the script code, you ae setting teh ref id as col B.

if so pls change this 0 to 1 in the sheet2, deploy it and tryagain