Your First Script – Apps Script Tutorials


ARUN NAGARAJAN: Hello,
and welcome. My name’s Arun Nagarajan, and in
this video tutorial, we’re going to talk about building
your very first Script. So this is a great tutorial
that we have in our developer’s site. You can find it very easily. So if you go to developers.googl e.com/apps-script, it’s the
very first 5-minute Quickstart. So very first script,
and here it is. And you should actually look
through the tutorial a little bit to get the sense for all the
different requirements and some of the background
information you need. The important things are having
some familiarity with JavaScript. You don’t have to be an
expert in JavaScript. And also, of course, you need
to have a Google account of some sort, a Gmail account, or
if your work is on Google, you can use that account as well. And the goal is at the end of
this, we’ll have a functioning script that does a couple of
interesting things that you could then take and extend it
as you please or use it as a starting ground to understand
how Apps Script works, and you can start from scratch
from there on. And yes, so this kind of
introductory information about what a Script is, I think a lot
of it is worthwhile for you to peruse through. In this particular video, we’ll
just kind of roll right ahead and start coding
pretty quickly here. And the very first thing you
want to do is open up a tab and go to script.google.com. And you can do this in
any modern browser. I’m using a Chromebook here,
and it could be Internet Explorer 9, 10, or Safari,
or Firefox as well. The very first time you go
to this URL you may be prompted to log in. You may even get a
welcome screen. Just make sure you find the
Start Scripting button and go right into it. And here it is. This is our Script Editor. And for this particular
tutorial, I’m just going to copy and paste the code from the
tutorial document itself. So we’ll go back to this tab,
and you can see that the screenshots kind of show
you what the Script Editor looks like. And here’s the function
that we care for. You can see that. It’s a very few set
of lines here. Even with spacing, I think we’re
talking about just about two dozen lines of code with a
lot of comments and spacing. And you can see that the
function itself is called Create And Send Document. So you can suspect what
this is about to do. So I’ll go ahead and hit Save. So the keyboard shortcut for
that is Control-S, or you can hit the little Save
button as well. And I’ll call this my first
script, save that. And you notice that the dropdown
here, populated with the set of functions
that we had here. And the only function we have
here, of course, is Create And Send Document. And that’s it. I think we’re ready
to run the script. We’ll talk about what’s in the
script itself in a little bit. Let’s see it in action first. I’m going to hit this
Run button. Now, this is very important. So when you run a script,
you have to give it some authorization. And when you run it from the
Script Editor itself, it has to take the authorization
of the script owner, the developer here, which
is yourself. So you have to authorize it. This does take a couple
of clicks. But it’s important to ensure
that we get the security part right. So the very first time
you run it, it just authorizes the script. You have to run it once more in
order for you to actually get the script to do what
you want it to do. So I’m going to hit the Run
button, which is the play button that you’re used to from
other script environments or coding environments. And that’s it. In this particular
script, we’re not showing an interface. We’re not actually displaying
anything back. We’re just running behind
the scenes. So let’s go take a
look at my Gmail. So you’ll notice that I have
a new email in my inbox. The number one popped
up there. When I click into it,
here’s what it says. It says “Hello for my first
Google Apps Script,” and it sends me a link to a document. I’ll click into it, and I’ll see
that it is just a regular Google document populated
with some content. And just to confirm, if I go to
my drive, I see a document populated there as well
when I ran this. So let’s now go take a look
at the script itself. So you can see that just in the
few lines of code, what we were able to do is create a
Google document, add some contents to it, get its link,
and then send it as an email to a person that I want
to send an email to. I think in this case it’s
sending it to myself. So very succinct set of code
here to get you started. Create a document, append some
content in a paragraph, close it, get the URL, get the email
address of the person that’s running the script, and then
using Gmail app, send them the link to that document. There’s the email address. There’s the subject, and
there’s the body. So hopefully, this kind
of got you started. This was probably your very
first Google Apps Script. There’s a lot more of what
Apps Script can do. Go take a look at our
documentation. Go walk through other tutorials
that we have. And we’re very excited to
see what you can build. Thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *