How do you Delete the data Spreadsheet using app Script?

image

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

I hope u can fix it

  1. make sure you put a Web1.Get block in your "Clear_Record" button event.
  2. Script should be like this (but see 3)
function doGet(e) {
  return ManageSheet(e);
}

function ManageSheet(e) {

  //READ ALL RECORDS
  if ( e.parameter.func == "ReadAll") {
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheetByName('Sheet1'); 
    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
   else if (e.parameter.func == "Delete") {
    var record = e.parameter.id;
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheetByName('Sheet1');
    sh.deleteRow(parseInt(record) + 1);  
    return ContentService.createTextOutput("Success, Record Deleted");  
  }
  
}
  1. The delete part of the script will only work if your id matches (+1) the row for the item. You can handle this by getting the index of the item in your list (selectionIndex should work)

ok. I Will try the codes

Like this?image

Yes, like that.

have you tried. is it works?

I have try but it still on the same error.

it still the same error. @TIMAI2

1 Open the script project
2 Go to Publish
3 Deploy as Web App
4 Project version: - select New from the dropdown
5 Execute the app as: your google account address (email)
6 Who has access to the app: Anyone, even anonymous
7 Press the Update button

You have to do this EVERY TIME you change your script

yes I have followed the steps. but it still can not work. I want to send file.aia in here

I made new file script.

When I click the button the error messages are rised image

DELETE.aia (3.2 KB) maybe you can solve it

Set the responseContent to a label so you can see what is returning. It will not be a list it will be the string: "Success, Record Deleted" so you don't want to put it in a list....

Your aia project file is useless, because there is no script URL included for testing.

sorry what you mean. sorry again I don't know to fix it better. maybe you can fix it to help me?

You deleted the app script url block

where is deleted

You have also deleted the global variable dataset