[MUSIC PLAYING]
CHRISTIAN SCHALK: Hi, I'm Christian Schalk, an AppSheet
product manager.
And today, I'll be stepping through a workshop
on how to use AppSheet's new Apps Script connector.
So let's get started.
OK, to get started with the workshop, what we're
going to do is I'm going to create a new project
in the Apps Script environment.
So click on New Project.
And incidentally, this will be the project
that we're going to be calling from from AppSheet.
So I'm going to give my project a simple name like Hello World.
And let's go ahead and add some code into the project.
So I'm going to add this function here called log this.
It takes a single parameter, which is a message,
and then it just dumps it to the log,
where it says message from AppSheet
was et cetera, all right?
So this is a very, very simple project,
but I'm going to now switch over to AppSheet
and build an application with an automation that can actually
call this function.
And it will also pass on a message to it all right.
So to build an application in the AppSheet,
the easiest way is for me to start
with a simple spreadsheet.
And so here's a spreadsheet which
contains a lot of different data points for ordering t-shirts,
for example.
Just so happens that I can click on Extensions
and then AppSheet and then create an app, all right?
So I'll click Create an App, and then now that's
setting up a new application based off
of the data that was in that spreadsheet.
All right, so in a few seconds, the app is going to render.
So this is actually the application
in a preview format.
So I'm going to now click on Customize.
So I can then go in and start doing updates
to the application.
So on the right, we can see the preview of the app.
If I went to click on a record, so this is the exact same data
that we were looking at in the spreadsheet, but now,
I can go through and change things.
So for example, I have these nice dropdown options.
I can change the color of an order of a t-shirt and such.
So it's basically a fully functional app in this case.
Now, what I'm going to do now is create
what's known as an automation, and the automation
is essentially a way for me to trigger a workflow based off
of a certain event or events.
And then I can assign it a task to do something
based on that event.
So in my case, I want to create a new bot,
such that, whenever a record is changed, I want to call--
in this new example, I want it to call an Apps Script
function, all right?
So let's go ahead and do that.
So I click on New Bot, and I look down here
and I can see some of the suggestions.
And this first one is actually perfectly usable.
So when a copy of the t-shirt orders example record
is created or updated.
In this case, it's going to send a notification.
In our case, we just want to update that to actually call
an App Script function, right?
So here's the step where it sends a notification,
and that would basically be it.
So I can actually jump to the tax part.
And here's the actual fulfillment of that workflow,
where it sends a notification.
And instead, I can actually tell it
that I want it to call a script instead.
So this is the new preview feature,
and I'm going to just name it call a script.
Sorry for the caps lock.
There we go.
And the table-- everything is the same.
Now, I just have to select the Apps Script
project that I created.
So I click on that, that opens up the drive picker,
and there is my project ready to go.
So now that it's selecting the project,
it's going to fetch any available functions to run.
And because I gave it that one function in my Apps Script
project, I should be able to see that.
So there we go.
Function name.
I'm going to select the Log This, along with the message
parameter.
And now, I just have to specify what is the message that I
want to send.
So I can say hello from AppSheet.
And that evaluates.
And once it evaluates it.
It says, yes, this is a valid expression in AppSheet.
Incidentally, if I wanted to actually put
in data from the back end sheet, I
could do that using an expression there,
but for this case, I'll just keep it simple.
And let's go ahead and save the app.
And now in order to trigger this automation, all I have to do
is select any record and update it.
So for example, if I select this record and I
click on the Edit link.
And I say maybe I want to change the color, change
one of the options there for the t-shirts, and I'll click Save.
And this is actually going to fire
the automation, which should then be calling my Apps Script
project.
So to see if it actually executed, let's go back
to the Apps Script environment, and I click
on the Executions tab here.
And then there we go.
I can see that I have this Log This function that's
being called, and there we go.
We have the message that's coming from AppSheet.
So there, you can see in just a few minutes,
I was able to create a new Apps Script project,
create a new function, and then I
could go in and create a new AppSheet application
and connect the two together.
All right, so hopefully, that was rather easy to do.
OK, for step 2 of the workshop, what I'll be doing
is I'm going to be exploring the Apps Script AppSheet Examples
project a bit.
And you'll see, once I get started,
I'll have a couple of different examples
to choose from for connecting AppSheet to Apps Script.
So first off to get going here, I'm
going to make a copy of this Apps Script Examples project
that we actually published a while back.
And so this takes us over to the Examples project.
And I'm going to click on the Copy icon,
and this will give us our own copy of this project.
And so I'm going to rename it something like--
I'll just call it something simple
like My new AppSheet Examples blah, blah, blah, project.
So here we go.
Now, we have this project.
We have a number of different functions that we can try.
So before I get started and switch back to AppSheet,
what I'm going to do is run--
I'm going to click on the Run button
and that will trigger the authorization step.
And so because the actual functions
are attempting to use like email, Drive, Calendar,
and such, I have to do an authorization step
where I review the permissions.
So we'll give that a chance to run,
and so this is common with Apps Script projects.
So there's the different services
that I want to be able to use from this project.
I'll click Allow, and then we're good to go.
So now, I have a new Apps Script project.
So now, I can go back to my AppSheet app
that I created earlier, and then I
can point it to this new project.
So instead of the old Hello World
that I created on the fly, let's point it to the new project.
In this case, it's My new AppSheet Apps Script Examples
project.
I'll click Select.
And then once that evaluates, I can then
choose a function here.
I'm going to start off with the Create Calendar function.
And then instead of having just a simple one of the title,
I want it to actually be my awesome new event for that.
And then what I'm going to do here
is I'm going to select a date format, which
I think should be OK.
So I'm going to select this format,
but I'm going to update it a little bit.
So let's go over here.
I'll click on the start time.
So I'm basically specifying the start time and the end
time for my event that I'm going to create in my calendar.
So I'm going to select April 6.
I'll put 19, so it's a 24 hour clock there.
That evaluates to correct, and let's set the end time
to instead of the 19th, let's do it at the 20th, all right?
So I'll click Save, and there we go.
So now, I have my new call to one
of the new example functions, which
is to create a calendar event.
And so I just happen to have my Google Calendar right here.
There's no events, so we're good to go.
I can go back to the AppSheet app.
I can click on one of my records to trigger the automation.
So all I have to do is just change
some of the data as before.
I click Save, and then that will trigger the actual automation.
So I just go over to my calendar, and there we go.
So we have this new awesome event
that's scheduled for tomorrow.
Cool.
So that was easy.
So let's go ahead and move on to a next step.
So in this case, I'm going to select the Create Doc example.
So if I take a quick look at the Create Doc example, which
is right here, all I have to do is just provide a doc name.
So that's pretty easy.
And it's actually going to create a new document entirely
within Apps Script, all right?
So to do that, let me just go ahead
and I'll retain the same project, but now,
I'm going to select the Create Doc.
And let's give it a new doc name.
So let's say my new awesome doc.
Close the quotes.
We'll leave it as such.
We'll hit Save.
And then as before, all I have to do here--
actually, I'll go ahead and save the app for safe measure.
And let's go here.
Let's click on the Edit Record, and I'll change the color.
Hit Save, and I go to the project.
And this one, I have to actually consult the executions.
And here we go.
We have my executions, and there we have the Create Doc.
So this is actually putting out a little bit of code
into the logs.
And it lets us know that we actually
created a new document.
And I just open up that document, and there we go.
So that's the new document that we
created from Apps Script via a call from AppSheet, all right?
So pretty straightforward stuff.
Let's go ahead and move on to another function.
So if you recall from our examples here,
I'm going to do the create sheet call.
So if I switch back over to our code
just to have a quick look at the code,
I scroll down to create sheet.
There's another function, and I just
have to give it a sheet name.
So let's just set that up.
I go to my application.
Instead of create doc, I'm going to create sheet.
All right, and let's give it a sheet name.
So pretty straightforward.
Click Save.
I'll save it over here as well.
And let's go ahead and update a record.
Hit Save, and that will trigger the execution.
So I go over to my logs.
And once the sheet has been created,
I should see a new update to my logs.
And there we go.
So it's still blinking, so I know that it's functioning.
I'll give it a second or two to finish up.
And now it's completed.
I pop that open, and now, we have
a new sheet named My New Sheet, and I
can open up the link here.
And there we go.
So it executed just like we expected
with that same new customized sheet name, all right?
So this is all pretty straightforward.
Let's do one more example just to hit home the different types
of scripts that we can call.
So if I go back to my code here, I
see also that we have a create slide deck.
So this one's a little bit more involved.
It'll have a deck title, a slide image URL, and a slide title.
So these are some things that I'm going
to specify in the parameters.
So it just so happens that I have some information here.
The most important thing is the image link here.
And I'm actually going to copy that image link.
I won't show it to you just yet.
I'll leave that as a little surprise towards the end.
So to do the update, let's go back into our application.
Instead of creating the sheet, I'm
going to create the slide deck, and I'm going to say--
I don't know-- my awesome new deck.
So that would be the first parameter.
This one is a important parameter for the actual slide
image that I'm going to insert and a slide title.
This is a nice puppy.
And I'll leave it at that.
All right, so click Save.
And we will again trigger the automation
just by updating the record.
I'll do maybe some quick updates, and I'll click Save.
Now, let's return back to our Apps Script project
and check the executions.
And here we go.
We got the create slide deck.
And it's already completed, and so I'll just hit the Refresh.
And we should see our output once it's finished.
There we go.
Successfully created a new slide deck here.
So let's take a look.
There is my awesome new slide deck.
And then ta-da, we have a new slide there
with our image of a puppy.
Cool.
So hopefully, this gives you an idea
of how you can work with Apps Script and AppSheet
together by using the new AppSheet Apps Script connector.
OK, so before concluding, there's
one final function that I want to show you
in the Examples project.
So let's go down to the bottom, and you'll
see here we have this create and send document function.
So let's go ahead and call that one from AppSheet.
And as you can see in the code here,
it's actually going to create a new document
and then it's going to send an email with that document
attached to it, all right?
So let's switch back over to AppSheet.
And instead of the Create Slide Deck Call,
I'll call the Create and Send Document.
And I'll pop open the Expression Editor--
a new document.
I'll just give it a simple title,
and that evaluates correctly.
And then here, I just put some example text here.
Here is a new email with new document.
All right, that will be it.
I'll click Save once that evaluates.
And we should be good.
There we go.
I'll click Save over here.
And incidentally, I have my Gmail window up here,
and so I'm going to use that to see if my document was created,
all right?
So let's go ahead and update our record
or change the color or whatever.
I'll click Save, and that should kick off our automation again.
And now, I'm going to be focused on Gmail.
And we'll just wait for the incoming update.
There we go.
And here's the new document.
And we actually have a link to our new document as well.
So I click on the New Document, and there we go.
So that's our actual document that we
got created in by calling this particular function.
Thanks for joining this workshop on AppSheet's new Apps Script
connector.
For more information on this important new feature,
check out the link below.
And thanks for watching.
[MUSIC PLAYING]