Getting started with Google Apps script
The first thing to note in relation to Google Apps script is that you need to have a basic level of coding experience to deploy a usable and working Google Apps script.
Google Apps script uses a version of JavaScript, so if you are familiar with JavaScript already then this could be a good environment for you to create some useful workarounds in the Google workspace domain.
What you need to know about Google Apps scripts
Google Apps script is a great environment to create and manage simple scripts on the Google Cloud, it doesn’t require any DevOps or server configuration or maintenance to run, and an apps script can be built and deployed by anyone using any of the main Google office tools such as Google Docs, Google Sheets, Google Calendar and so on.
There are limits to what Google Apps allows you to build, and there are security considerations and usage limits that you need to take into account.
Google Apps script is a great environment for simpler scripts that could boost your productivity, but if you require a very complex solution that uses a lot of interdependent platforms then it’s likely that Google Apps script won’t be sufficient for your needs.
Google Apps scripts have a limited runtime which means that if your script takes a day to run, then it’s likely it will time out and stop before the script has been completed; so it’s important to build a script that is efficient and completes in a timely fashion.
Creating your first Google Apps script
You can create a Google Apps script within your most commonly used Google products such as Google Docs & Google Sheets, and you can also interact with other Google products via the various APIs that have been developed by Google.
To start a basic script I think it’s easiest to start building from a Google Sheet, as spreadsheets often focus on input / output values and the cell structure makes it easier to understand how a script is operating and can help with debugging a script that might not be doing what you expect.
How to create your first Google Apps script
Step 1: Open Google Sheets
If you are a regular Google Sheets user then you can just type ‘sheets.new’ and hit enter in your Google Chrome URL bar and a new Google Sheet will be opened.
Step 2: Open the Apps Editor from the ‘Extensions’ menu
In Google Sheets, click into the ‘Extensions’ menu and click ‘Apps Script’
This will open the Apps Script editor view and should just an empty function
At this point you can name your project by clicking on ‘Untitled project’ at the top of the view, this will make it easier for you to find and manage Google Apps scripts projects in the future.
Step 3: Name your new Google Apps script function
It doesn’t matter what name you give to the function at this point, but as with all programming problems it’s best to give it a sensible and logical name that is easy to remember. When you come to use your function you may need to type the name out in a formula so try to avoid very long or hard to spell function names.
Step 4: Writing your JavaScript function
At this point you have a blank canvas for your function and the default function will not make any changes to your documents or interact with any other services.
As with all programming projects it’s best to have a problem in mind that you need to solve, and then think about the steps that you might need to go through to solve that problem.
In my example my problem is that I need to add 2 to every value in my Google Sheet. Yes, I could very well just use a standard formula include a ‘+2’ to increase the value by 2, but for the purposes of this tutorial I will write a script that does this for us automatically.
In this example i’m using ‘input’ which is the cell reference value from the Google Sheet, and simply adding 2 to increase that value before returning it.
Step 5: Test your Google Apps script
You can see below how this works in the Google Sheet, my function name is the formula name, and the ‘input’ value is cell A2, with the formula value returned being the original cell value increased by 2.