Reader small image

You're reading from  Google Apps Script for Beginners

Product typeBook
Published inFeb 2014
Reading LevelIntermediate
Publisher
ISBN-139781783552177
Edition1st Edition
Languages
Right arrow
Author (1)
Serge Gabet
Serge Gabet
author image
Serge Gabet

Serge Gabet has been a professional audio equipment manufacturer for 20 years and is now working for an artistic upper school in Brussels, Belgium as a teacher and Technical Manager. He is also in charge of the Google Apps administration of this school. He develops custom applications using Google Apps Script mainly for his school, though he also works in other areas. He has been designated a Top Contributor by Google since June 2011. He was active on the Google Group Help forum till 2012, then on the Stack Overflow forum (the Google Help Group forum was closed in June 2012), and became a first ranker and an all-time contributor on the Stack Overflow forum a few months back.
Read more about Serge Gabet

Right arrow

Chapter 5. Embedding Scripts in Google Sites

As you probably know, Google Sites is a free service included in every Google account that allows the creation of Google websites. These free websites have a URL such as https://sites.google.com/site/siteName/pageName, but if you have a Google Apps account (education or business) and a domain, you will be able to customize this URL and even create e-mail accounts with an @domain.xxx address.

We are going to consider only the standard accounts without domains as they will be use cases for most of us, and Google Apps for business is a subject for another book on its own.

This means that some methods will be unavailable; if that is the case, the documentation will always mention it clearly (https://developers.google.com/apps-script/reference/sites/sites-app).

To start with creating a site, log in to your Google account and go to the URL https://sites.google.com/site/ that will show you all your current sites, if you have some, and suggest that you should...

Site gadget's limitations/restrictions/use cases


Site-embedded web applications are a nice way to give access to your script functions because they enable easy page navigation and the possibility to add descriptions, directions for use, and illustrations, making your apps easier for other users to use.

If we think about the very first script example in Chapter 1, Enhancing Spreadsheets, that calculated my age in hours and that we tried in a spreadsheet, the same script modified to work as a site gadget would be much more fun and easy to make public without us needing to share any access to any of our documents. Moreover, even a user having no experience with spreadsheets would be able to use it without difficulty.

The code will need to be changed to create a small and basic user interface so that users can enter their birth date and time. This requires a few methods and a workflow, which we haven't talked about yet (it is for the next chapter), but for now you can simply copy it and follow...

Creating and maintaining sites with Google Apps Script


As mentioned earlier, script gadgets are only a small part of Google Sites; the interesting feature of Apps Script in Google Sites is its ability to create and modify the site itself with a script.

Imagine you have a site for your restaurant and that you publish a new menu every day that follows a predefined scenario: pasta on Monday, beef on Tuesday, and so on. You would normally edit your menu page at the end of the day so that it is updated every morning with the right menu. This is a typical example of an annoying repetitive task that a script could easily do for you.

Create all of the daily menu's contents in some document, maybe a spreadsheet. For example, take the time to create a nice-looking template in a Google document and write a script that will update the site automatically every night based on the template and the spreadsheet data.

This might seem hard to do, but we'll use methods that we've already tried and proceed step...

Creating pages


The previous example actually doesn't have many SiteApp service methods as it again makes use of a combination of sites, documents, and spreadsheets, which is one of the major interests of the Google platform. Google services are always available and tend to exchange data to and from each other (https://developers.google.com/apps-script/reference/sites).

We could have got almost the same result using a different approach and using only SiteApp methods.

In that workflow, we'll need to create a second website with restricted access rights in which we are going to create seven pages, one for each day of the week, with a menu description on each page.

In this case, we could have a different layout for each day, such as varying font styles and background images.

From there on, the only thing we have to do is copy the appropriate page to our public website every day, just like we did in the first example.

This can easily be achieved using the template feature in SiteApp. Each page will...

Interactivity


The example shown here can be viewed online. A form can be filled in, and the site's user list will be updated. Feel free to have a look at the following link:

https://sites.google.com/site/gettingstartedwithgas/home

Different sources of data can be used to automatically update Google Sites as follows:

  • Forms: These can be embedded, and their responses can be used to create or modify pages

  • Calendars: These can be embedded, and it's easy to retrieve data from them to update a page

  • Spreadsheets: These can be published to web pages, but when they are published, they don't work as spreadsheets anymore and are just visible as pages; if you have edit rights, you will be able to see a link to open them in the normal spreadsheet interface

  • Text documents: The same comments apply to text documents, as we saw in our example of the restaurant menu

  • Script gadgets: These can be embedded as well, and from there on, you will be able to perform any data manipulation and site update possible

Another...

Summary


Although this chapter was meant to be about Google sites, it actually demonstrates the multiple features and advantages of the communication and combination of multiple services provided by Google Apps Script.

A Google site on its own is not very different from other sites. In many aspects, it is limited in layout compared to other platforms. However, its ability to integrate scripts and exchange data with every other Google service makes it a lot more interesting.

We have also had the opportunity to use a few interesting JavaScript features that we will surely use multiple times, and it is definitely motivating that we have a chance to get our hands on the user interface tools in the next chapter.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Google Apps Script for Beginners
Published in: Feb 2014Publisher: ISBN-13: 9781783552177
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Serge Gabet

Serge Gabet has been a professional audio equipment manufacturer for 20 years and is now working for an artistic upper school in Brussels, Belgium as a teacher and Technical Manager. He is also in charge of the Google Apps administration of this school. He develops custom applications using Google Apps Script mainly for his school, though he also works in other areas. He has been designated a Top Contributor by Google since June 2011. He was active on the Google Group Help forum till 2012, then on the Stack Overflow forum (the Google Help Group forum was closed in June 2012), and became a first ranker and an all-time contributor on the Stack Overflow forum a few months back.
Read more about Serge Gabet