I was working on a Google Apps Script project lately in Google Sheets that set up parameters in a sidebar and then ran the process once the user clicked the “Submit” button. The problem was that the process was taking a while and that “Submit” Button was ripe to be clicked multiple times by the impatient user, before the server-side code could even finish it’s operation.
To fix this I needed to disable the submit button once it had been clicked and then enable it again once the server-side process was complete. Here, I need to:
- Do something awesome with it server-side.
- Upon the completion of the server-side awesome, call back to the html file and enable the button again.
I have a very simple Google Sheets Side Bar with a “Submit” and “Cancel” button. When the “Submit” button is clicked it calls the function
submittington (can he get any more creative? No. No he can’t).
This function then disables the “Submit” button sends a variable to the client side code.gs and displays it stylishly in the sheet multiple times for the users viewing pleasure. After the code.gs function is executed, it calls back to the client-side
submittington function and enables the button.
Behold!!! The example:
Continue reading “Google Apps Script – Disable Enable Submit Button in Sidebar”
*.gs and Html files
Then, what’s the trick?
Instead, we will need to use the templating method:
html = HtmlService.createTemplateFromFile(filename)
We will get into a little more detail on templates later in this tutorial.
My main reference for this was the Google Apps Script UI best practice guide, and you will see code snippets of the first example there that I have modified for my own example.
The thing is, the explanations were a bit vague for me to work out clearly so I really needed to create an example of my own to work through how to use it. The example below breaks down the steps to create file relationships to make your code look neater. It also dives into some uses of template statements in html.
The Final Result
Take a look at the demo:
What if you want to get a value or a range from Google Sheets and show it in your sidebar using Google Apps Script?
First you will need to get the value or range by using Googles server-side script. Then you will have to display it client-side in your HTML document.
Documentation on getting the server-side and client-side talking nicely to each other is a little vague. Hopefully, this very basic tutorial will help clear things up.
In this tutorial I will also be using Jquery.
Let’s get started.
Continue reading “How to Get Something from Google Sheets and Display it in the Sidebar in Google Apps Script”