Delete the listview selection from googlesheet

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

@Spicy_Topics i just changed it but didnt work, lets try the second sheet in the aia file you created maybe you figure it out so it just needs to be same as the sheet 1, thanks in advance

@Spicy_Topics here is the aia file you created
Sample_Jai.aia (3.1 MB)

lets test there sheets sript codes in same as you made before

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.