Hello, I am trying to delete some row of data from my google sheet using a query function and I have read taifun's tutorial on it but he used a on form submission and was wondering if I didn't use it, would it make a difference. Would the script have to be different as well? This is because I already have a query script for the sheet where it helps to read the data and sort is ascendingly. Here are my blocks for for just calling the data, I want something similar but to delete like using the query "DELETE from Sheet1 where A matches 'data', B matches 'data':
As you may have seen from the documentation for the Google Query Language there are no "action" SQL functions such as INSERT or DELETE.
What you can do is add another function into your web app to handle the deletion of rows and send the request from the app: (assumes aData will be found in Column A and bData will be found in Column B)
function doGet(e) {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var aData = e.parameter.aData;
var bData = e.parameter.bData;
var rg = sh.getDataRange().getValues();
for ( var row = rg.length-1; row>=0; row-- ) {
if ( rg[row][0] == aData && rg[row][1] == bData ) {
sh.deleteRow(parseInt(row+1));
}
}
Set a Web1.Url with your parameters and use Web1.GET
aData and bData are supposed to be strings and not lists - oh, I can see that is what you are sending.
So what is not working.....
I didn't add a return section to the doGet(e) ?
function doGet(e) {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var aData = e.parameter.aData;
var bData = e.parameter.bData;
var rg = sh.getDataRange().getValues();
for ( var row = rg.length-1; row>=0; row-- ) {
if ( rg[row][0] == aData && rg[row][1] == bData ) {
sh.deleteRow(parseInt(row+1));
}
return ContentService.createTextOutput("Rows Deleted");
}
Please show the blocks that call the "WebApps" web component (your "POST"), and also a full copy of your web app script, in text (not an image), and an image of your data on the spreadsheet.
Okay thank you so much this is the only bit left for me to finish my Final Year Project and i'm sorry I do not know how to put a code in a listview thing? in kodular there's one button that shows </> but in here when I click on it, it doesn't seem to help make the code easier to read