Google sheet delete one record function not refreshing table after delete action

Hi,

I am not sure what's the best way to describe the issue in the subject but hopefully the screenshots better explain the issue I have.

I created a block that reads data from google sheet and also delete one entry.
Here's my google script:
gscript.txt (2.7 KB)

And this is my read all records button, it works fine:

This is my delete button
app2

This is the screen of my app, I click a row (it would highlight yellow) and the pressed delete
app3

After I pressed delete, the yellow cleared off and nothing seems to happen
app4

However, the record actually gets deleted in the google sheet
app5

I am expecting the Web1 get block would refresh the table in my app screen after the delete is completed but it appeared it could not do that.

I have an update button which pretty much do the same thing and that seems to work fine. I think it may be the sequence of events or something but can't figure out.

Any help would be greatly appreciated, thanks a lot !

Try calling Web1.Get in the Web3.GotText block - what is probably happening is Web1.Get is running before the delete takes place.

The code could be much more straightforward, and you could use just one web component....

Thanks Champ @TIMAI2, that works! yeahhh!
Thanks for pointing out the webcomponent too, ok I will try to change it to use one component.

You can edit your delete function in the script to return all the records after the delete, something like this:

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

To return the table data from the sheet as a stringified json list:

....
var rg = sh.getDataRange().getValues(); 
      } 
return ContentService.createTextOutput(JSON.stringify(rg));
1 Like

Amazing. Thanks a lot friend for the extra mile help!

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