Unable to delete or load data with Sheets

Ok thank you! So to delete the row with value searched, would it be this?

Before you delete make sure you are getting the exact row.

But the above blocks are correct, sounds good

(Note:You can achieve this using single web get request with the help of script url and no need of api)

I don't understand what you mean by exact row, also when I try to emulate the app on my phone everything works until I delete a team (It exits out of app)

First web get request to get exact row number

Second web get request to delete the obtained row number

And this apps scripts deletes exact row based on the matching data with col B by sending single web get request

Like this?


I tried it and it still exits me out of the app on my phone when I press delete.

(also my MIT App Inventor shows 1 warning and 1 error but I can't find them in the code)

Remove the web1.GET on both and try

it still exits me out of app. One time I saw a notification say "given URL is not valid"

Do You want to delete the row by web get request? (Scripturl) or by spreadsheet component?

I want to delete the row that has the chosen value (listviewer selection)

for ex: If I chose team A, then whatever row says "team A" would delete.

All the rows to be delete whichever col B has the text Team A?

I imagine that the text present in col B and in such case, in your existing codes pls add this and deploy it once again then through script url method delete it.

function deleteAllRowsByColumnB(dataArray, sheet) {
    var values = sheet.getDataRange().getValues();
    var toDeleteValue = dataArray[0][1]; // Extract Column B value (Index 1)
    var deleted = false;

    for (var i = values.length - 1; i >= 0; i--) {
        if (values[i][1] === toDeleteValue) { // Check if Column B value matches
            sheet.deleteRow(i + 1); // Delete row (1-based index)
            deleted = true;
        }
    }
    
    if (deleted) {
        return ContentService.createTextOutput('All matching rows deleted successfully.');
    } else {
        return ContentService.createTextOutput('No matching row found.');
    }
}

Or share your existing code in which i will make changes and give you

Screenshot 2025-03-23 4.19.18 PM

here you can see the data is in column B,
All rows are listed in listviewer too,
if user selected a certain team (for example, row4 Varsity girls soccer)
row4 would be deleted.

ok I will try code.

It seems you will be sending partials data, in such case you should try this code

function deleteAllRowsByPartialColumnB(dataArray, sheet) {
    var values = sheet.getDataRange().getValues();
    var partialText = dataArray[0][1]; // Extract the partial text from Column B (Index 1)
    var deleted = false;

    for (var i = values.length - 1; i >= 0; i--) {
        if (values[i][1] && values[i][1].toString().includes(partialText)) { // Check if Column B contains the partial text
            sheet.deleteRow(i + 1); // Delete row (1-based index)
            deleted = true;
        }
    }
    
    if (deleted) {
        return ContentService.createTextOutput('Matching rows deleted successfully.');
    } else {
        return ContentService.createTextOutput('No matching row found.');
    }
}

what do I do after the code is deployed
How do I use scripturl method to delete?

Is there any way to delete selected data without code?

After listview picking 
Set web2url to script url?+partialText={ListViewSelection}
Call Web2.get

When web2 got text
If get response code =200
Then set notification to "Success"
function doGet(e) {
    var sheet = SpreadsheetApp.openById("YOUR_SHEET_ID").getSheetByName("YOUR_SHEET_NAME");
    var partialText = e.parameter.partialText; // Get partial text from the URL parameter

    if (!partialText) {
        return ContentService.createTextOutput("Error: No search text provided.");
    }

    var dataArray = [[null, partialText]]; // Format data for the delete function
    return deleteAllRowsByPartialColumnB(dataArray, sheet);
}

Your sheet name is not Sheet1.

See the dump procedure for the real name.

You still need the proper credential file to do a component delete row.
(The Get Sheet block can work without it.)

By the way, this is how you prevent blank input:

I replace the AND with an OR.

(Besides lining the two clauses up for readability)

There is also a problem with how you remove a row.

The filter result is a LIST of row numbers.

The remove row block can only accept a single row number, so you have to check if the list of row numbers has a list length > 0 and then use item 1 of that list as the row number for the delete row.