In the last lesson, we saw how we can access bound script and then write some code within the script
editor and add content to the document.
So this lesson, we're going to be using a standalone script and we're going to do the same format where
we're going to select the body and then append some content into the body.
So for the standalone script, I'm go over at script, dot, Google, dot com and home start.
So I'm going to go ahead and just create a brand new project and that's going to open up the editor
and we just give it a name of standalone doc and then within the function and I'll call it add to Doc.
So first thing we need to do is select the document object.
So just as we did with the bound script, we use the doc up and then we specify what where the doc is
located so we can select it by ID and as well as you URL.
So let's track the ID and the ID of the document is available within the Web URL.
So it's usually the easiest way to select and get the ID of the URL through the URL there so you can
select it and it's just past the deal.
And then that long set of characters before the edit is your document ID for that specific document.
So now that we've got the document ID, let's use the document app and open by ID and we also have the
option to open by your URL.
So that would be the full web URL of the document.
So within the document app it returns the document with the specified ID.
So let's add the ID into the dock up and within the logger will go to the contents of dock just to make
sure that we do have it selected properly.
So let's run the script.
We're going to have to provide permissions to the app.
So this is a standalone and it's not related to the one we did in the last lesson.
Let's accept the permissions.
Select the account that you want to provide the permissions with and then hit the go to standalone app.
And then here it's going to give you information about the permissions that you're adding.
You can also hit the information icon to get more information about the various permissions.
And if you want to remove out the permissions, you can go to the my account dot Google dot com forward
slash permissions.
And from there you're going to have a listing of all of the apps by their names.
And from there you could remove permissions.
So we've got connection to the document.
And once we've got the connection to the document, we can select the document and we can write some
content to it.
So just as we did with bound script, we need to select the body object and this will give us the opportunity
to add content to it.
So get the body of the content and then within the body, we can add paragraphs, we can add tables,
we can add list items, we can as a horizontal rule.
So let's do a paragraph first.
And right out.
Hello, world, and then also it's in the body.
We're going to spend a horizontal rule and then body append page break method and save and let's run
the script so we already have some content in there.
So this is the new content that we've added.
So there's the paragraph, there's the horizontal rule, and then we've got a line break for the next
set of content.
So just after the horizontal rule, we've got a page break.
So breaking it into another page.
Also with script you can create documents and creating documents is really easy to do.
So let's create a function.
I just call it create my doc.
And then within this function, we're going to select the document object and using the document app
creates and this is the method that creates new document and it returns the new document object.
So we need to provide a name so it's expecting a strong value for the name, I just call it New Doc
Tester and that's it.
Just what the one line you can select and you can create the doc and then we could actually do what
we did here as well.
And what I'll do is I'll take this out as a string name.
And I just call it my name, so be a string value and then we'll use the variable name of my name to
create it and then also we'll concatenate it when we're adding the paragraph.
So let's try it and create my duck.
So select the next function, create my duck, and we're going to run that function and execution completed.
So let's see what happened within the drive.
We've got a document that was just created.
So it's new Doc Testor.
So let's open that up.
And then within the new Doc Testor, we've got the paragraph, we've got the horizontal break and then
we've got the page break.
So that was all done on the fly with the Google map script creating a document.
So the objective of this list and the previous lesson is to get familiar with selecting the document
that you want to use.
So these are all the document objects.
Once you select the document object, you can get the body of the document and from there you can provide.
And get additional information, let's try one more where we've got the create new document and I'm
going to update this to let and we're creating the document object and we want to get the ID of the
document.
So within the log or log the dark object, we can use the get ID to return back the ID value of the
document.
And also, we can set the name of it so we can actually rename it to something with the.
So how about we update the name of the document?
And we're going to add to it, so just do a concatenation of it and add it to it and then we'll set
the name.
So just use a space there.
And the name to my name, so that way we're going to include the newly created document ID in the name,
try that and run that.
So we created a new doc and then we've added and updated the name of the document.
And when we open that, we see that we've got the content there and we've got the ID of the documents.
So this ID actually matches what we've got up here.
And how about we try one more?
We'll get some more information from the doc, so in the logger log, the doc object.
We can also get you out of the dark if we want.
So how about we add append a paragraph within the body, append paragraph and within the paragraph content,
we can output the doc your URL and we'll do a few more so that we're producing a dock with a whole bunch
of useful information about the document itself so we can get the viewers.
We can get the name of it as well, so I do need to have the rounded brackets in order to invoke the
method.
So we've got the name of the document
and I'll do I add in some string values here.
So we've got some more context to what we're adding and then we'll produce the document.
And in this case, so we've got the name, we've got the Eurail, we can get the editors.
And what I'll do is I'll actually I'll log out the editors in the log.
So let's see what happens when we run it one more time.
And so within the editors, we've got the editors there.
So first we're logging out the ID, then we're logging out the URL and I forgot the round of brackets,
so it didn't actually get the euro there.
Let's go back into the drive and we're going to see what we've logged out.
So we've got hello, world and Tester, the euro with the euro value.
So it matches with what we've got for the URL up here within the Web URL, we've got the name Tester
Dock's.
So that's going to be the name of the document.
And the editor is going to be presented.
Even though this is an array, we're able to see the contents of the array as we output it and within
a string format into the document.
So that's going to correspond with what we have here with an execution log.
So this way you can produce a document and have some additional information about the document, including
updating the name as you're creating it with some of the values that are associated.
And some of the properties are associated by Google for the document itself.