Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Google Apps Script for Beginners

You're reading from  Google Apps Script for Beginners

Product type Book
Published in Feb 2014
Publisher
ISBN-13 9781783552177
Pages 178 pages
Edition 1st Edition
Languages
Author (1):
Serge Gabet Serge Gabet
Profile icon Serge Gabet

Table of Contents (16) Chapters

Google Apps Script for Beginners
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Enhancing Spreadsheets 2. Create and Manipulate Forms 3. Managing an E-mail Account 4. Embedding Scripts in Text Documents 5. Embedding Scripts in Google Sites 6. Standalone Web Applications / User Interfaces 7. Using User Interfaces in Spreadsheets and Documents 8. How to Expand your Knowledge 9. Conclusion Index

Chapter 6. Standalone Web Applications / User Interfaces

It is sometimes useful to write standalone web applications that can be shared across offices or with other users; these applications would need an intuitive user interface. This chapter will teach you how to build these interfaces.

If you are a Google Docs user (and if you read this book, you certainly will be), you probably like the ability to share documents with friends or co-workers, but you would sometimes like the option to not share every part of it.

For example, it would be nice for one to be able to see data about themselves on a spreadsheet, but not all the data about everyone. As we experienced before, spreadsheets, for example, can be selectively write-protected, but there is no way to hide ranges selectively depending on the user viewing it.

We could imagine some workaround by copying part of the sheet to a new one and sharing this one, but then we'd have to take care to synchronize these sheets. When we have many people...

UI or not UI, that's the question


Spreadsheets and text documents are by nature very powerful and well-designed interfaces; they are the result of many years of expertise from Google and other previous designs as well, but for some use cases there are just too many possibilities.

If you have already found one of your cherished and carefully prepared documents completely messed up by someone after you gave them access to it, you'll understand what I mean.

It is not always a question of malice or wickedness but, very often, a simple matter of incompetence.

Building a user interface with restricted possibilities solves that problem radically; it just requires a little more work from our side and that's what we're going to try now.

This chapter is about standalone web apps and UIs; we'll see that there are also many situations in which we don't need a user interface and others in which applications respond to parameters or even work entirely on their own without any user interaction.

Common concepts...

Limiting user access


Let us return for a while to publishing web apps, which we explored at the very beginning of this chapter: we saw that we could deploy them to run as myself and used by either Anyone or only me.

That's actually the first level of access limitation, but sometimes we would like to give access to some people we know and prevent everyone else from using it; this basic limitation is definitely too basic.

There are a few ways to get the result we want; the following are two simple examples.

When we deploy an app as User accessing the web app, the user will be asked to authorize the script to get his e-mail address (or more information if the app uses other Google services) and information about who is using it.

In this case, we can easily place a condition on this e-mail address for it to be compared to the list of authorized users. The following code for this is very simple:

var email = Session.getEffectiveUser().getEmail();
var client = ['serge@gmail.com','mary@yahoo.com','william...

Protecting your data (and your script)


We have seen in the previous section how to prevent an unauthorized user from accessing your web apps. However, in some cases, we would like to allow users to use the application, but not to be able to modify our script (even accidentally) or open a script-related document.

With reference to the first point, we should clarify again some aspects of file sharing and app sharing to be sure that there is no ambiguity in your understanding of the concepts:

  • In standalone apps, the script doesn't need to be shared for a user to run the app (but, in spreadsheet- or document-embedded scripts, the permissions for the script are the same as those for the container).

  • If an app is running on the User accessing the web app option, each file for which the script can read or write must be shared with that user too (or be public or shared with Anyone with the link).

  • Note that the code itself doesn't need to be shared for an app to be shared. Don't share your code if it...

Summary


If we consider Google Apps Script as a toolbox with plenty of different tools, the tools we introduced in this chapter are probably the most powerful and useful.

There will indeed be many occasions when we may want to execute some simple (or not) tasks without using a full-featured spreadsheet: standalone web apps are the solution. Since they can easily be shared across offices or with other users, they also present us with a good way to preserve our privacy.

It might seem a bit complicated, but after a short while, we get pretty familiar with their structure and simple apps take only a few minutes to write.

Now that we understand this new possibility, why not try to integrate UIs in other documents? That will be the focus of 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 2014 Publisher: 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.
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}