Button in Google Sheet to 'Clear/reset'

Hi,

In previous posts it’s clear that Glide is working on a feature to allow users to clear data and perform a reset. But no news on when this valuable feature will be available.

In the meantime, can anyone share a workaround based on inserting a button directly in the Google Sheet? I have never worked with scripts but I assume this is the way to go. Does anyone have an example that would do the following:

  • Button that allows users to Clear/Reset
  • A warning appears before execution
  • The range of rows or cells can be configured
  • The action would clear pre-defined ranges in multiple tabs
  • Ideally the action would not touch rows containing “=”, e.g. formulas - Although this is a ‘nice to have’

Lastly, can I assume the script would not interfere with the Glide App?!

Thanks in advance for any help!

Regards,
Simon.

This is all doable with a script, and it could be triggered from Glide if you want to go that way.
If you prefer to trigger from the Google Sheet, then I think I’d tend to favour a menu extension as opposed to a button.

I have some scripts that clear entire sheets (minus the header row) that I could share almost immediately.

If you wanted something that addresses all of your points, I could create this for you, but I’d probably need a day or two.

2 Likes

Hi Darren,

Thanks for the great response. Sounds promising. Can I just ask, would the menu extension work only on my version of Google or would anyone with the sheet have that access?

Anyone with Edit access can run scripts (or create new ones, or edit existing ones).
Folks with View access cannot do any of the above.

2 Likes

Then that sounds perfect. I want to be able to share a copy of my Glide App and then handover ownership of the Google Sheet, preferably with a feature to reset/clear some rows.

So if it worked through the menus, what would the user see? Could there be a new menu option added?

If you can share an example I could copy/import I would be super grateful!

1 Like

Thanks to everyone above for their input. However, I think I have found a good solution - at least better for me, since it requires no script editing!

  1. Insert a graphic for a button into the Google Sheet, e.g. [RESET]

  2. In the menu, select Tools, Macros, Record Macro…

  3. Perform the required set of actions, e.g. clearing cells by selecting and deleting values and save the macro

  4. Select the button icon, click on the 3 dots to open the graphic menu & select ‘Assign Script’

Now every time the button is selected the macro runs and it performs the reset. It even works on multiple sheet tabs at the same time.

I recommend beginners practice on a duplicate Sheet before working on the actual sheet. I love this since it requires no scripting. I understand the script might also be triggered via an event in a Glide App, but for now this is my simple workaround solution.

My next step is to check that when my Glide App is copied the sheet can be copied with the reset button and script included. I’m assuming yes… let’s see.

1 Like

@Simon_Hill I love your solution for this. I am VERY new to Glide and need a way for a button in Glide to uncheck all previous checkbox selections. Is there a way to activate a script from a button in Glide?

You could do that with an ‘onChange’ Trigger. Here’s an example where I use a named range in sheets… only when that named range is not blank will the script fire. I clear the content at end of script to ready it for new.

function csv_sheet_change() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var trigger = ss.getRangeByName('CSVTrigger').getValue();
  if (trigger != '') {
    console.log("Sending CSV");
    emailCSV();
    ss.getRangeByName('CSVTrigger').clearContent();
  } 
}

Courtesy of @Darren_Murphy

This is also something you could consider.

2 Likes

I now prefer this better way to clear columns:

I also had almost the exact same thought. However my Apps Script abilities are very limited. Maybe you can help me since your script looks like what I want to do.

Here’s the layout of my app. I work with and mentor college students, and it’s an app to help me understand where they’re at and help them process as well. In the setup a user will scroll through a list of “cards” and select a few they think are most applicable for the context they’re in. Later this list is presented to the student and they select two they feel describes them the most. So I have a UserSelection tab and an AudienceSelection tab. The AudienceSelection populates with what is selected by the User and each has a column of checkboxes.

I was able to make a button in Glide that toggles the checkbox to True on the selection screens using “Set column values in this row.” So here’s what I’m thinking (again I’m very new to Glide). There will be an introduction screen to the app with a “Let’s Go” button. That will have custom action set to Toggle a checkbox in my Setup tab to true, then again to false (I do both to make sure it actually changes), then open the UserSelection tab. In sheets there’s an App Script for OnChange to clear the named ranges I have for the checkboxes on UserSelection and AudienceSelection tabs. Does this make sense?

I haven’t read Jeff’s article yet. I glanced at Simon’s and I think I have too many selection options for that.

@Simon_Hill this is a really creative and easy way to do it if I didn’t have so many selections. There will be 2 separate selection screens with up to 12 options on each. Still probably doable…but I feel like there has to be something a little more elegant haha.

1 Like

@Jeff_Hager Ok this looks exactly like what I might need… I haven’t used IF/Then in Glide yet and I’m just getting the hang of Relations but I’m pretty sure I grasp what’s going on. I opened your app and copied it to look at how it works. One thing I don’t understand: When the app is opened it has a blank screen (the RichText?) and a “Tap to Start” button. How did you hide everything else behind that? This is definitely something I could use in the app I’m making!

That’s just a visibility condition set on all of the components on the screen. If the Parent ID is empty, then the rich text and start button show. If the Parent ID is not empty, then all of the other components are shown on the screen.

Ahh. I didn’t realize that was an option! Thanks for the tip!

1 Like