Calling a script from a button

Hi! Is there a way to call a script of google sheets from a button?

I already have scripts onEdit and onChange band they are working well. But I could not find a way to call another function from a button so that no changes are needed.

Thanks a lot for your help!

@David_mrflda I have used a combination of a switch and a timed trigger. The timed trigger runs every minute and the function it calls looks at the status of the switch. If it is true it runs the script function I want and then sets the script to false.

Thanks @George_B, I was thinking on something more intuitive like a button but since this seems not possible your proposal could work.
Is there any way I can add the switch at the bottom of a list of items?
At the end what I’m looking for is a way of deleting all the items of a list on a user action (ideally a click button, or a switch as an alternative).

@David_mrflda You would just add the switch component underneath the Inline list component. If you are not using an inline list comp but just displaying a list view of a sheet I can’t think of a way to add the switch (or a button - see below) to the bottom of it.
Theoretically you could do it with a button (open as link), but it would involve writing a Google script webapp. Which involves a bit of HTML and scripting, and possibly not worth the time involved.

There is a way to add a switch below an inline list. What you need to do is create a new sheet that contains the value that would be controlled by the switch and read by the script. That new sheet will replace the tab that you are using in your app. Change the style of the tab to Detail view, add the inline list component and point to your existing sheet, then add a switch component that points to the column in your new sheet. A checkbox component would also be a valid option. This should then work fine with onEdit/onChange events.

I thought I said that, but glad you detailed how to change from a “normal” list view to a detailed view with imbedded inline list(s).

1 Like