Getting Started with Google Apps Script New IDE online Editor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey welcome to our google apps script introductory course my name is lawrence i'm going to be your instructor for this course i come to you the many years of web development experience as well as many years of google apps script experience and i'm ready to help you learn more about google apps script i am a google developer expert and i really do enjoy working with google apps script so what is google apps script it's a rapid application development platform that makes it fast and easy to create business applications that integrate with the google workspace so if you're using g suite or if you want to get started with using more of what g suite and the google services has to offer then google apps script is the place to be you write code within modern javascript so if you are familiar with javascript code it's going to be really easy to pick up and start writing code with google apps script you can also access and take advantage of the built-in libraries access all of your favorite google workspace applications like gmail calendar drive docs sheets and a whole lot more the best of all there's nothing to install it's free all you need is a google account log into your google account and get coding so google apps script can allow you to increase your productivity automate your tasks and automate some of the stuff that you're doing within your google services you can add custom menus dialog sidebars have custom functions and macros within sheets publish web apps as web urls either standalone or embedded within google sites creating standalone or bound applications also interact with other google services such as youtube adsense analytics maps connecting to the various google apis build add-ons in order to extend what can be done with google docs sheets and other google services and best of all it's really easy to get started with and now more than ever there's a more powerful new ide that lets you do even more and increase your productivity making coding even easier debugging and updating and writing your code in the upcoming lessons i'm going to be walking you some of the basics of coding with google apps script and as well as we're going to be running through what's new and improved with the ide the online editor for google apps script so let's get started coding and checking out some amazing things we can do with google apps script hey in this lesson we're going to be providing a quick overview of what google apps script does and what it is and how you too can get started with google apps script so first of all you do need a google account so you can go ahead and log into your google account and to open up the google apps script editor there are a few options so you can either open it up and by going over to google.com forward slash script forward slash start and hit the start scripting so that's going to open up the apps script project area and from here you can select new project and this is going to open up the new i ide so that you can start scripting as well you can go and go into your google drive and there's that new project that we just opened up so this is gonna sit within your drive if you are using a standalone project and that's the ones that are not connected directly to uh google suite apps service so this one is going to be standalone and it's got the indicator here with the arrow pointing to the right hand side so that's the logo for the app script that you're going to see within your drive and when you give this project a name you can give it a name and that's going to show up as the file name within your drive and then that way you can easily access it so the other way to create a new google apps script project is open up the drive and then within the drive hit new and under new more and select google apps script so this as well is going to open up the apps script editor and allow you to create another new project so just give it a rename and always when you are selecting names select something that makes sense so that's easier to access and that you can always go back to it and find it within all of your projects and this as well gets created within the drive and then the third way to start and creating code within google apps script is to work with a bound script so bound scripts are available within docs sheets and slides so let's open up a bound script within google docs and the difference between the standalone script and the bound script is that the google service so in this case docs is going to be serving as the main container for the google apps script so within your drive you're going to see it created as a docs file and in order to access the app script you have to open up the doc and then go to tools and select under the tools script editor and this is going to open up that same ide now it's not creating a separate file because this is contained within the docs and this is going to be as a bound script so there are some advantages to bound scripts that we can interact with the docs active content as well as we can interact with the docs ui whereas when you've got a standalone script then you need to connect to the google service that you want to use and you don't get the same options with the ui so it depends on the project that you're creating if you're looking for having interaction directly within the dock the sheet or the slides and you want to add menu items then create a bound script so that's creating either the dock the sheets or the slides and then going into the tools option and script editor and then accessing the apps script that way or if you are just creating an automated project you can as well connect to any one of the docs sheets slides and any number of the google services and do the same coding that you're doing within the bound script so other than that the similarities are the same that the editors are going to work the same way it's just you've got some added functionality with the bound script so let's give this one a name of tester3 and just rename that and so that's still going to be contained within the drive within the dock but if we go over to the main apps script home and if we go to the newly created projects you're going to see that you do have tester 3 we have test 1 and test 2 and this is going to open up the same ide so this is going to allow us to open up the ide that way as well so once we've created the script within the doc we can access it within the script.google.com site and this is going to give us a listing of all of the projects that we're currently are working on so let's do a quick recap of what we've covered in this lesson so we saw that we can create a standalone script so standalone script is any script it's not bound to google sheets docs slides or forms file or sites these scripts appear among your files in your google drive so just as we saw here they just appear as separate files in the google drive and the creating of the standalone script so the number of ways that you can create the standalone script and this gives you more information about uh what you can do with the standalone scripts so with the bound scripts so these are container bound scripts so as we saw with the docs so these can be created in google sheets docs slides form files and it's created in the document rather than a standalone script and that's why for the bound scripts it's referred to as a container and a script as being contained within the doc so that's why within your drive you're not going to see a separate script but if you do to go to all of the scripts within your script projects you will see the doc listed there and that means that there's a bound script contained within that doc and once you do create a bound script so one of the disadvantages is that they cannot be detached from the file as they are bound to that file and they gain few special privileges over the parent file so there's something to keep in mind when you are creating a bound script so that it's always going to be attached to that file and they do have special methods so they do have a listing here of what the bound scripts can call a few methods that the standalone scripts can't so it's got the get active sheet get active document get active forum and the get ui so this is adding in to the ui menu of the particular document there's also within sheets it's got some added options where you can get the active range in the selected areas and within docs you can get where the cursor is positioned so it gives you some more additional options and there's also options for same as with the ui where you can create menus dialogs and sidebars so go ahead and log into your google account and create a script create a bound script as well as a standalone script and you can be ready to move on to the next lesson we're gonna look deeper into what we can do with google apps script google apps scripts allows you to increase the power of your favorite apps so this is a listing of most common apps used so calendar docs drive gmail sheets slides so if you are a google apps user you're going to really power up your google apps and also automate with google apps script so there's a lot of resources and documentation over at the developers.google.com forward slash apps script so listing of code examples and also more details about how to work with google apps script there's a lot of guides so rich guides that will detail all of the different methods and all the different wonderful things that you can do with apps scripts so you can create and add custom ui options so menus dialogs and sidebars and that's with the bound script you can also write custom functions and macros within google sheep you can publish web apps so those are standalone web applications that you get a url that you can share with others and that's going to be all driven with google apps script you can interact with various google services and there are a lot of google services to interact with so if you're using adsense analytics calendar drive gmail and maps you can easily connect these together and log things out into sheets and so on and building add-ons to extend what you can do with google docs sheets slides so with to increase your personal productivity you can update and create custom add-ons and also create add-ons for the marketplace and you can also streamline the google chat and also convert an android app into an android add-on so that it can exchange data with the user's google doc sheet and mobile device it's a lot of really cool things that you can do and whether you're creating a standalone script or a bound script so it's going to be driven by what exactly you want to do with the script so i'm going to provide a quick overview in this lesson about where to get information and get additional details help uh within the and this is the place to go to the developers.google.com so they do have a lot of code examples and as well if you want some sample codes there's a samples here within the menu so you can select the apps script samples so it's got a lot of really neat samples that you can try out and go through and as well if you want to check the reference so if you're looking for a particular google service or a method class so you've got a listing of all the common workspace services such as calendar contacts there's docs drive gmail slides spreadsheets so these are all the common workspace services and if you unclick these this is going to provide you the google class and also an overview of what this particular class does and then a listing of all of the wonderful methods that provide that power within the google apps script so these are all methods that are available and it's got a brief example as well as a listing of what is available within the methods there's also google advanced services so these are some more advanced functionality that you might be looking for within google so you can even connect to the youtube api using the google apps script connecting to your calendar so this is a more detailed action on the calendar itself and also some of the more common google services that are available so the advanced services and then there's also script services so script services provide you advanced and added functionality within the script itself so this is where you can create web apps and templates for the apps also communicate from the client side back to the server side there's also things like the charts that you can generate card services that you can create for add-ons there's different services like the cache base service so the logger for debugging now we've got the console log as well so if you're a javascript developer the code is going to be pretty much the same as what you're writing with javascript other than you've got access to all of these functions and methods that are available within the google classes so you're really bringing in a number of classes and then providing functionality through those classes by passing through data and a lot of the common stuff that you can get with javascript is also available such as date random and a lot of the different methods that come with javascript are available within google apps script so it's got a listing of these as well there's also the ui option and this is for the bound scripts that you can update and create menus and they've got a basic mail function so this is slightly different than the gmail because the mail app allows you to really easily send emails so this is the syntax for it so you can do a mail app send email and this will send an email to the email address that's specified here and as well it's going to have a reply to option and subject option so most of the methods here they do have a code examples as well as how to use them and how to implement them and what the parameters are so in this case it's expecting a string value so we've provided a string value or an example they've provided a string value the reply to the subject and the body they're all string values and you can also send html emails within the optimization there's also properties service so this allows you to store content there's a url fetch so this is just like the javascript fetch that allows you to fetch different web content and web page content there's the script service so this is the one that provides you the access to different service scripts such as running different triggers you can set up triggers and the triggers are used for the automation there's also a number of utilities so the utilities are just useful methods that help you do some conversion encoding decoding formatting json manipulation and just different miscellaneous tasks so there's a lot of options here within the reference and this is where you're going to find most of the information that you need under the reference tab there's also a samples tab there's a support tab so this gives you information on what the latest updates are there's also a community area issue tracking and uh stack overflow connection there so you can go out to there and also search for different code snippets as needed within the add-ons so it tells you how you can create add-ons and how you can work with add-ons within the google services there's also the apps script api service so to give you more information about what you can do with the rest api and creating different rest apis for your projects so before the next lesson so head over to the developers.google.com and check out some of the sample code as well as the reference and the guides area and you can be ready to move on to the next lesson we're going to dive into the editor and the functionality of the editor this lesson we're going to be writing some code with google apps script so let's go over to the script.google.com forward slash home forge slash projects and hit the new project and create a brand new project i'm also going to increase the size of the editor so that's easier to see while i'm doing the recording now of course you don't have to do this you can keep the size as desired so just going to give this one a name of tester script and that's the way that's going to show up within the drive you can also go over to your drive and just make sure that you do have the script there available and we're going to be writing some script so this is the ide you can minimize and you can make the file area larger and smaller there's some numbers and we're going to be going over all of the options with the ide in the upcoming lessons so this lesson was just to create our first script so the way that google apps script works is you've got a series of functions and then you have an option to run the various functions and this is what provides the script functionality and this is just like javascript within the cloud so if you're familiar with javascript then you're should be pretty good to write google apps script so let's create and let's just use this first function and give the function a name so just call it my function 1 and we're going to run through some of the functionality that's available so in this function what we want to do is we want to create a doc so giving a variable name and i'm going to just call it doc now of course you can call it whatever you want this is just a regular typical variable i'll make this one size bigger so we're at 200 percent and then using the document app service class so we can select it from the menu and there's also within the i it'll give you more information about what's available so this is within the document app so let's go ahead and select the document app and then when we create so we'll do the dot it's going to provide us the menu option with all of the different methods that are available to us so what we want to do is create a doc and the parameter that is required here is a string value and this is going to be whatever we want the name of the dock to be so we'll call it test one and then go up and save the project and now we're ready to run the project so let's run the project and within the execution log so this is going to give you information about what's happening behind the scenes the server as it's running the function and it is going to ask us for permissions whenever you're accessing or whenever your script is accessing any additional functionality or any of additional services that you have so whether it's accessing the drive or the dock or the sheet or any of the other google services you're gonna have to provide permissions for it so you can always as well remove the permissions that the apps the script has to your account so let's select the review permissions and first it will ask you to sign into a google account that you want to use and in this case i'm just going to be using this default one that i'm also creating the script with we can also just continue to the script so let's select the account that we want to use and because this app is one that we're just creating we get this warning message that google hasn't verified this app and it's accessing requesting to access google account information and until the developer actually verifies the app it shouldn't be used so this is a warning message that you're going to see on all of the apps you have an option here to go either go under advanced or back to safety back to safety will just boot you back to the ide and it won't actually let you run the script so if you do want to run the script then you have to go through the advanced and here it's going to allow us some more details about what permissions we're accepting so continue only if you understand the risks and trust the developer and because i am the developer of this app so i'm pretty good with this and go to the test script so this is going to be corresponding to the name of the script so we've got the tester script and that's also the name that we were using so let's select that and now it's going to tell us what permissions the script is asking for and it's going to run as this user account it's going to allow us to run the test script so the test script content and it's asking for the view manage your google docs documents so that's the set of permissions that it's requiring because we're using the document app class and we're accessing the google docs documents so we also have some more details here about the various risks that we're taking and if we ever want to remove the permissions you can always open up the google permissions and that's going to give you a listing of all of the permissions that you've got so that one actually didn't run so let's stop it and we'll try to run it one more time and we'll run through the permissions quicker this time so under advanced and that's because i clicked off on the google account uh and once you're okay with the permissions that you're providing hit allow and now this will actually execute the application so we've got the notice so the time that the application executed and when it was completed so what happened and when we go over to our drive we've created a brand new file and whatever name we had within the whatever name we had here so we have test one we created a brand new document with test one so there's the document that we created and this one's a blank document so let's create one another function and this one can be my function too and this time we're going to create another document but we're going to write to that document using the google apps script so now that we've assigned a variable and because the document app create has a callback of the newly created document object we can now reference it with the name of doc so we select dock and we've got the drop down of all of the available methods that we have and within the dock we want to write some content to it so we're going to get the body of the document and that's going to get it as another object so a lot of times you're going to see that we've got another object for the document body and if we use the logger log that's for debugging so we can output those objects and this in itself will just be a document object so we want to write to some content into it so let's select the new body object and here we've got some options so we can append a horizontal rule we can append an image a list item a page break a paragraph or a table so these are some of the basic structures that we can add to the document i'm going to do an append paragraph and within the append paragraph it does require one parameter and that's going to be a string value the content of the paragraph so let's do a hello world as the content of the paragraph and then save that and we're gonna run function number two and we've already accepted permissions for the document app so we're able to run that without having to accept permissions again so once you accept permissions you can run it and those permissions are going to be persistent you can always remove the permissions for by going over to the myaccount.google.com so it's going to list out all the apps and allow you to remove permissions so let's head on over to drive and see what we've got for test two so there's test two and there's some content within test two so once you create the document so every document within google has a unique id so the id value and the easiest way to select the id is just go up to the url of the document so if we want to not create documents but simply select existing documents and append a paragraph or write to those we can do that as well so going over to test one the one that we originally created we're going to select the id from the web url go back over to our project and let's create one more function and this function can be my function three so that it's in line with other function names and this time we're gonna use the id of the document so assign a variable name i give the id for the variable name and i'll move this up a little bit so it's easier to read and now this time instead of creating a doc instead of using the create doc function we're going to take the const and assign a variable doc you don't always have to use doc of course you can use any variable name that you want so selecting the document app class and we want to open by id and the parameter that's expecting is the id value so let's just drop the id there and i'm also going to use the logger log which is the same as the debugging tool so you can also if you're familiar with console log it's the same idea where it's going to output content into the log and the logs what you see when you execute the app so let's try that and we'll do a my function 3 and we'll execute it so we selected the document object and next let's select the body so the same way that we did here where we've got the document object and the body and let's uh run that one more time so now we've got the document body section so we're at the same state that we were here when we're creating it and now let's take from the body and we'll copy that function and we're going to append a paragraph and you can also get the callback on the paragraph as well so let's uh output the paragraph here and run function three so it's got a paragraph object and now if we go over to test one there's our newly created paragraph using the google apps script so whatever we want within hello world let's run that one more time and go over to the doc one so there's our hello world two and whatever times you run it it's going to continuously add new paragraphs and once you've selected the paragraph object there's also different methods that are available for that so when you select the paragraph you can append some additional text to it so let's add in some new text and use the append text method and run that function one more time so there's our newly appended text there and it's rich with a lot of different functionality that you could do so the idea is that you either create the containing google service that you want to use in this case we're using the doc or you select an existing one and then you can manipulate it so once you've selected it select the body content and then you can update the existing content and you can add new content to it so coming up i'll go through a few more classes with google apps script in this lesson we're going to be creating some additional example code so let's open up the editor and we'll use the same file that we're using the last time so this time we'll call and create a brand new function so call it my function number four and got a prefix set with function so that indicates that we're expecting a function here and by the name of my function for so we can select that now with the google services there is some there is a way to get whatever the active user is so we're currently using an active user and that's how we log into the google apps script and are able to create ax script so in this case this is my email address that i'm using so i'm going to send myself an email using google apps script so first of all i need to get the email address and there's a way to get it from the session service so selecting the session service and this gives you a drop down of some of the options that you have so you can get the user you can get the active user so selecting the active user is going to return back to active user information and gets the user's email address so the get email and if this is allowed within your security policies now if you are using the google services if this is company based google services sometimes the admin might lock down some of the options within google apps script so keep that in mind and i'm just using a regular gmail account so this is just a regular google account a free account so i do have access to it but if you don't see that option to get the email that's because the administrator has locked it down so what is being returned here is going to be the active email address if you want to see that email address you can do a log or log and it's always a good idea as you are writing scripts to make use of the logs because this will give you information about if you've actually got a variable and also helpful debugging so let's run the function number four and we'll get the current email address and we do have to provide permissions for this as well so let's just go through the accepting the permissions as we're adding in additional permissions to the tester script so selecting and adding in permissions it's going to allow us to get the email address so it outputs it as a string value so once we've got the email we can send ourselves the email or an email to that account so let's uh select the content of the email and we can do that by actually let's uh send the content of the google document that we created in the last lesson and we'll send it via email so once again using the id of the doc to reference the document we're opening it by id and it's being returned back into the variable name doc and then we're getting the body object of the current dock by selecting the body content and if we do a logger log of the body content and run the function we're going to get this document body section so we need to turn the body and we want to get we want to edit as text and then selecting the method get text is going to return it back as text object so let's uh run that and there we've got our text object so we've got some content that we can send in the email and also we want to get maybe the name of the doc so that's another thing that we can get and i'm just going to actually add and select that as email content set a variable name for the email content as we're going to need this for the email itself and we also need a subject for the email so let's uh use the logger log selecting the document and get the name of the document so that's going to return back the name of whatever the current document is that we've selected with that id and that was named test1 and just as we get the name we can also set the name so if we want to update this to my email doc or whatever we want to call it we can also set the name so that's going to rename the document so now it's called my email doc and at this point it was still test one but if we run this function again now we've got the new name of the document so we can set a name we can get a name of the document so we've got all of the information we need to send an email we've got the email address we've got some content for the email and we've also got a subject for the email so let's select and create a variable called subject and this will just be whatever the doc get name is so whatever the that returns back it's going to return back a string value for the name and if we also want to get the url we can also get the url of the document so we don't have to open up the document as long as we've got the id we can select the document and just as we got the name we can get the id and we can also get the url so it's going to return back the url of the document so let's take a look and see what we've got here within the log so there's the url of the document and we're going to send all of this information in an email so let's create one more function here and call it url and assign a value to the doc and putting it all together to send an email we're going to use the gmail app service and the method send email and it gives you an example of how to send the email so it's expecting the recipient which is a string a subject which is a string and a body which is a string so it's the values the parameters that it's expecting so let's add those values in so it needed an email it needed a subject and it needed an email content which is the string value that we were using so email content which corresponds to there now we can also update and add to the email content and i do need to update this instead of a const to change it to let because we're going to be updating the contents of the email content so i'm just going to concatenate to it whatever the value of the url is so adding in a space let's not write together and there's our url so let's put it all together and what this function is going to do so function 4 it's going to get the email address of whatever the active user is and the active user is coming from the session class and the session class is what is created whenever you log into your google account so you don't have to always log it out but we were doing that as debugging we had a document that we created so we've got an id value for the document that's sitting within our drive we've selected the document by id into the doc object and then we're using the doc object so first here we're getting the body content and we want to get the body as text instead of an object otherwise we'll just send the object the object class name so selecting the body we're using a method to edit as text and that allows us to select the content as text and then here we're setting the name so in case uh it's not the right name whatever name we want to set and this we've already done so we don't we can actually skip over this step so just like with javascript you can comment out blocks lines of code with forward slash forward slash and then we're setting a variable name called subject which is going to be the name of the doc we're also selecting and getting the url and updating and appending that to the email content so whatever content is currently within the doc then that's the content of the email that we're sending so this is a string value that we're sending and then lastly we've got the gmail app class which is providing the method of send email that required a few parameters that we've picked up and we've dynamically generated the content for so save that and let's try running the my function so run the function and of course we do need to accept permissions because we're using the mail app service so we haven't accepted permissions for that yet so whenever you add different permissions then you do need to always accept those and right now we're adding in the read compose send and permanently delete email from the gmail so that's the permissions that we're adding and that's going to allow us to send the email so looks like everything executed properly let's go over to our google drive and of course every time you're accepting permissions you get a security alert that will give you more information about that the test tester script was granted access to your google account so this is just the security feature within google that every time you accept and grant permissions you're going to get an email and then here's the email that we sent so let's check it out and within the email we've got hello world hello world 2 2 hello world 2 new text and then we've got a link to the doc and then we've also got it as an attachment so this is a feature and this wasn't actually anything that we did uh it's whenever you're sending a google gmail it automatically will add a dock as an attachment if it's a dock within the drive so let's select and open that up and we can see that the text in fact does match exactly the text that we have we even have the space here app at the top of the email so it's gotten the content of the doc as text sent it as an email and also we've got the url of the doc and we've sent that and attached it to the text of the email so go ahead try it out and you can do some different variations and also try out some other methods that you see within the drop down so coming up next we'll do a run through of the editor and familiarize ourselves with how to write code within the google apps script id so that's coming up next hey in this section we're going to be going over what's new with the google apps script editor so the online editor has got a facelift in 2020 and going over some of the really cool features that now come with the editor and it's made it even easier to use it's been a huge leap forward for debugging more coding hints cleaned up interface as opposed to the legacy editor not to worry that the legacy code will still work within the new editor so if you do have legacy code you can easily switch over to the editor and it should also work seamlessly we've got some new features with debugging console log has been added for all the javascript functionality to be able to copy and paste directly your javascript directly into google apps script without throwing any of those pesky errors with console log there's also a new command palette which provides you some really cool features and allows you to add even more keyboard shortcuts so for more productivity and quicker coding the debugger and logger i've also had an advanced update more information with the autocomplete there's the right side menu so everything is all on one page you can switch to the editor also see the project triggers libraries services all within one cleaned up interface deployment has also changed and update and we can deploy we can see our test deployments and then we can manage existing deployments some of the really cool features that are now new with the ide and as well uh taking keep in mind that the older code will work if you do have any questions or comments i'm always happy to hear from you let's get started coding let's get started we're going to create a standalone script so going over to script.google.com and creating a brand new project and that's going to open up the ide and within the ide just at the top right left hand side you can select and you can rename your project so i'll just call it new project and hit the rename button so at any point when you've got a project you can do a rename of the project and update it within the project title area there's also the option to go back to the main apps script area so this apps script logo will take you to script.google.com forward slash home so that's the main home area for the google apps script there's also some options here to deploy the script there's a share option to share the project with others and when you share the project with others that's going to open up the typical google script sharing and google services sharing window with this a pop-up window where you can select and add additional people so if i wanted to select and add another person to have access to the script we can share that with them and you can add as many people as you want also you can check off the notify people and this will send a notification that this person has been added to the script uh they can be added in as a viewer or an editor and there can only be one owner for every google file so that's the current owner that is the owner and if you do want to change the ownership you'd have to go to the drive and update the permissions in addition to that sharing it as a viewer and editor will also allow the user that you've shared in order to be able to access the dev environment on web apps you can also create a new project from here as well so i'm going to go ahead and add this person as shared to the script and then when i go into the drive i can also update and get the same share permissions from the drive window so there's the permissions it's got the current owner and whoever created the file is the owner and also over here we've got the default person that we've added if we want to make this person the owner we can do it within drive where we can make owner we can change them to a viewer keep them as an editor or we can remove them entirely there's also an option down here at the bottom to share the link so you can set who has access so selling access to the link for the google script if you want to have the link shared with anyone as a viewer you can do that as well as you can set anyone as an editor to the script so i usually do suggest that you do not share with anyone with the link as keep it on restricted is usually the best way to go and that way you can fully control and you know who's going to be accessing your script project so there's also a support button up here at the top where the question mark is so the support button when you click that it's going to give you links to the documentation training also update terms of service and send feedback the documentation is going to open up the developers.google.com forward slash apps script so this is the website the go to place for everything google apps script where you can go under the guides and find out more about the different options here with script examples and then under the reference so this is where we've got the core google web space services so we've got calendar docs slides spreadsheets so you can check check out all the different classes there and then there's the advanced google services so this is where we provide a means to use the google api so it's not included with the google workspace apis because it's got a more advanced functionality than the regular workspace apis and this is just provides you thin wrappers around those apis so it's not the apis themselves there's more information about the advanced services here and then as well within the google web space services there's also at the bottom there's the script services so these are utility services that are not in connected to any particular google workspace product so you can use them generally across all the workspace products to provide some additional functionality such as logging information creating html compressing data and even more so that's what you can select under support there's also a training option so this once again brings you to developers.google.com and you can check out some example of google apps scripts code examples and then there's an updates area so again developers.google.com and of course you can always go to the main tabs here under samples or support so it brings you to that same website there's also an option here to switch back to the legacy editor so this was the original editor and this option will eventually disappear but it allows you to switch back to the legacy editor and if you want to switch or if you are on the legacy editor for most people it should be available to switch to the new apps script editor so you can always switch back to the new apps script editor as well so there is an option to go to the legacy editor and switch back to the new apps script editor and the top right hand corner just shows you the google account that has been logged in the new functionality so it's the new editor is a lot easier to read it's a lot easier to see the code it's got line numbers it's got indentation and it's got some more advanced functionality for debugging and so on so the lines have numbers you can also right click to reformat the document so in case we have some values here and i'll just create some script here so set a variable of a to be equal to six and this actually should be logger log so uppercase for the log and if for instance we're not aligned we can always select and right click and as well on a mac if you press the control and click the left click that's going to open up this pop-up window where you've got an option for getting definitions going to references and we are going to look at these there's also peak so we can peek at definitions and references we can rename symbols and just down here at the bottom we're in the middle we've got an option to format document and if we've made a selection we've got an option for format selection so what this does is this realigns it so basically it beautifies the code so it's a lot easier to read and this is one of the nice advancements here that this is more like an actual editor that you might be using offline and it's brought into the google cloud editor for apps script so there's that formatting option where we can realign so it allows you to automatically format there's also some more options here where we can format the entire document so let's say for instance we've got a few functions and we want to do a formatting of the entire document we can select that and that's going to realign the text and the code once again and correctly make the indents on the code so basically it's allowing it to be easier to read there's also for collapsing the functions so if you've got a number of functions so you've got a bunch of code here and oftentimes whenever we've got a lot of code when we're looping through it it's easier to read if we can collapse the functions so if we want to look at one particular function and maybe we've got a lot of content in here we can collapse the other ones and focus in on the one that we're looking at and this now has been provided with the new ide as well so the ability to make the collapse and then of course uncollapse them and ext expand them once again and they also do have the standard options that we saw before so there's typical things that you can undo and redo so we can undo the edit you can go back several levels and then also the redo as well like you can go back a few times until you get to the current state and then the redo is going to gray out so when you run out of states to go back then you're going to have the um it's going to get grayed out so you're not going to have that option anymore there's a save button so you can save the project at any time there's also the run option so what the run does is this is going to run the function that's selected within the drop down here it's going to pop up the execution log we can also shide and show and hide the execution log so if you don't want to see the execution log you can select run and in the drop down select one of the functions and hide the execution log so we can hide show the execution log as needed there's also the option to debug so it works the same way as run and we are going to look at this a little bit more detail in the upcoming lesson but for the debug you once again you select the function that you want to run and you can run the debug on the function and it's going to open up the debugger on the right-hand side so you can also set breakpoints and we are going to do that in the upcoming lesson so those are the core options for the main menu and coming up next we're going to look at the debugging and also more about the autocomplete within the new ide so again try it out open it up and write some code and do some realigning of the code by control click and do a format of the document and also make a selection and do a format of the selection and you'll be ready to move on to the next lesson this lesson we're going to be looking at how to debug our application so one of the ways to debug it and especially if you're setting a lot of variables and if you're making some updates to the variables using the logger log is an excellent option to output that the current state and current value of any of the variables and i'm going to just copy this out a bunch of times and we can also even create a for loop for this so just as we would with javascript let's create a for loop and we're going to run this a number of times so while it's less than 10 increment i by one and then within the for loop we'll continue to update and add to a and then we'll output that in the logger let's uh clean this code up as well and because this is indented within the for loop let's make a selection and format the selection and notice that it does indent it to the next level save and we're ready to run the my function so let's uh first run it within the run and within the run we get quite a bit of information within the execution log so anything that we're using within the logger log is being output in the execution log and now with the new editor as well we can use the console log so you can take javascript code and write it up in your editor and copy and paste it directly within the apps script and it'll still run the same way so it's uh now we're trying console.log instead of logger log so this is a method within typical javascript and it actually works the same way as the logger log so that's really a nice update with the new ide because now whenever we've got some straight javascript code previously if we would put in the console log it would throw an error because it was unrecognizing that method but now that console log has been defined within apps script it makes it a lot easier to take just basic javascript and copy and paste it from our offline editor from our local editor and directly into the apps script editor and then there's also the realigning of the code so with the debugger we can set breakpoints with the debugger so we saw in the last lesson that when we run a function with the debugger we open up the debugging there's more information if we click the learn more open up the tab and then if we go to the support troubleshooting this is where we can find out more information about the debugging and how to debug the application so common errors as well so service uh invoked too many times so that's oftentimes happens service not available so there's a number of reasons why service might not be available sometimes the google servers will just throw an error if they're having an issue and there's also debugging so oftentimes when the server is not available you might want to try the function another time or to isolate out some of the code in the function uh in case you're running some really server intensive code so sometimes that might cause that issue there's also authorization is required so that's if you've missed the pop-up window for the authorization you haven't provided the correct authorization to run the code so in case you are setting up triggers uh make sure i always suggest that you run the function at least one time uh before you set it to just run on the trigger because in case you're you save it and then you close set up the trigger and you leave it might need still authorization so you won't know if it needs the authorization until you've actually run the function and that way run the function before you set it up in a trigger there's also the access denied so this is again a permissions thing so in some cases you might not have permissions and oftentimes as you can see there's a number of ways that permissions will throw errors within the google apps script and permissions can be anything from permissions changing on a document that you're trying to access to permissions changing in general and then for general debugging use the logs in order to log out helpful information as the script is executing there's also for the status and debugger and breakpoints it shows you how you can add in a breakpoint and what a breakpoint does is this allows you to pause the script when it hits the break point at whatever line you've highlighted and maybe if you find that one of these values isn't coming through within the log and you want to know what the value is at this current state this is where you can set a breakpoint and then within the debugger you can check that out uh so it gives you some more information about um if you are having troubles with the script run it within the debug instead of the run and set the breakpoints on the script part that might be problematic so if we are outputting into the console log and we're wondering well why is a increasing and maybe we've got some type of issue here where we're taking a and we're setting it to a value of 10 and then within the log the error that we're producing is it's not incrementing it's set at 10 so it's not changing so we want to debug this and find out what's going on so we suspect that the problem uh is somewhere after this log ran because we started it with six then we got seven eight and then uh this one should be actually this should be six this should be seven and this should be eight and then we're incrementing a by one but we're only seeing tens output from this point so we suspect that there is an issue within the for loop so let's set a breakpoint on this line of code and then that way we can run it within the debugger so the way to set the breakpoint if you hover over the line number you see a little purple circle in this case and that allows you to set a breakpoint and then now when you run the debug it's going to tell me the different variables so i've got a variable i is at zero the local a is at 10 or 8 and then we've got all of the global functions that we have as well so we don't need to look at the global typically you're going to run into errors on the local stuff unless you're calling one of the methods that's not available and we see at this point it's eight so right now it's as expected we're going into the function that's eight let's uh resume it and now we see that it's gone to ten but we were expecting a code of nine so we know somewhere here is where the error has been caused and that way we can go into the script and we can say okay well that's the issue here that we're assigning a value of 10 to a so let's uh comment it out and when we do make updates to the code it will ask us to restart the debugger so let's restart the debugger so right now we're at eight next is nine ten and eleven let's uh also step over and you can also do a step in and step out so what the step in will do and the step out so that will step in and step out of the function of the loop so looping it back and now we're sitting at a is 13. let's take a step back so it brings us back to line number nine and then if we step in that's going to bring us to the next line if we do a step over that's gonna step over that particular break point and then it's going to move to wherever if we do have next breakpoint in which we do because we're set the breakpoint within the loop also we can resume it so the resume will continue so if if we've checked the code and if we're not seeing any errors and you can also resize these windows as well uh we can also stop the execution of the debugger we can get rid of the execution log as well and hit resume and then once we've gone through all the breakpoints so that's it so we've run through and we've done all of the break points and we've also been done some debugging of our application using the breakpoints so that's how you can use the debug function within apps script and this is a really handy function that allows you to really get into the code and find out exactly what line is causing any issues that you might be encountering and have that pop up on the right hand side with the debugger this lesson we're going to be looking at the autocomplete function within the apps script editor and when you are writing a function or a method it does have an auto complete option so let's create a brand new function and we'll just call this test one and then within this function we're going to set up a document and using the doc app so this is the pop-up where you've got some information so once you start typing one of the methods one of the classes you're gonna get a pop-up window that's gonna help you auto-complete and you can also get more information about this so this if you want to complete it you can just click on it and as well if you want to check out what additional information it gives you what interface it on the namespace the document app and it gives you also an example of the const document app and document app value so let's uh add in the document app and then the next autocomplete is going to give you a drop down of all of the enums as well as the methods that are available for the particular document app class so we've got an option to open it by id get the active document so that's with a bound script we can create one so let's select create and if we want to find out more about this also you might have noticed as well that we've got a red curly underline here and that means that there's something missing within this method because create is expecting a parameter for the name of the document that we're creating so let's add in a string value so this can be a string value for the name and when we do set variables if they haven't been used yet they're going to be grayed out and if they are dark black that means that they're in use so once we set a name for this variable we've got string name we haven't used it yet but we're going to use it to create the document using the string name so copy the string name variable name and then once we use it within the code we're going to find that the string name now goes black and whereas if we haven't used the variable that we've assigned it's going to go grey and that means that we're not using it within the code we're not using the callback function so we don't actually need it it's going to be the same thing the same idea here that we can set the code using the dock so if we're missing it we do get that red underline again and also you'll notice as well that we do have the red dot here on the right hand side so if that's if we do have any errors or issues if you do save it it will stay as underlined and when we do create a space you get this little light bulb here so you can check and it will provide you fixes fixes you can also get under the command by selecting the area that is underlined and on a mac you can press command dot and that will pop up this little window or you can select it once again just click anywhere where it's got the red underline and then go to the show fixes and this will give you two options so you can ignore this error message that will get rid of the red line or you could disable checking for this file so that will disable the automatically checking so in this case we want we know we want and there is does seem to be an error here for whatever reason and that's because we're not missing we're missing the string name that we're not making use of it uh also when we select the string name we can see that um it also provides us a hint that we can remove the declaration for string name because it doesn't detect that we're using it within the code if we do an ignore the message then the string name will go dark as if it was being used and then also we have the option to disable checking of the of the document so just using the string name here once again it's going to make it darker and allow us to create that document so within the dock let's do the drop down and see what options we've got so we can within the dock let's get the body content and get the body object of the document and here within the drop down suggestions we've got all the different methods that are available to us so in this case we want to append a paragraph and then once again within the pen to paragraph if we don't include a value a string value within a pen paragraph it's going to have the underline so let's add in the string and we'll use the string name and notice as well within the suggestions because we've declared the variable string name and if we start typing it it will come up as one of the suggestions of what we can use as a value from the drop down so let's select the string name and save it so run test one function review accept the permissions and what we're doing here is we're going to create a document with a paragraph that's going to also include the string name so let's go over to the drive there's our document that we just created and there's the appended content into the body of the document and you probably also noticed while i was typing there's uh autocomplete here so whenever we do the rounded brackets it's going to give us the method it's going to give us a definition of the method and the parameters that are required so the new document's name creates and returns a new document so in this case it's returning the new document back to doc they do have an example of how to the syntax so variable doc document app dot create and then it's got string value for the document name so it gives you a full coding example pop-up window of what to include within the parentheses here and in this case we're just going to include the string name value in there and create and use that in order to create a document so all of these new features where they've got the pop-up windows and helper windows that help you define and let you know what information this saves you the trouble of having to go over to your documentation and then flip back to your code where it's really presented within your code within the pop-up windows as the auto completes and then as you add in new variables they also get added into the pop-up window as an option for one of the variable names and this really does help with if you've got a variable that you're trying to remember or if you have a function that you're trying to run it's going to reference that function and allow you to easily make a selection of that within the pop-up window so these are the my functions that we created earlier so you can select the my function and run the my functions as well within that function and easily reference any function or variable name that you have access to within the scope of the function that you're currently creating and running so go ahead try it out i look from the drop down method list of all of the things that you can do with the various functions as well as try out what you can do with your variables and even with us string that we've just created it gives you the all of the different string methods that are available within javascript so we've got the trim we've got to uppercase to lower case so you can select from the typical javascript methods string methods as well and that's also included within the dropdown so it makes it really easy to see what's available for each one of the objects that you're working with in this lesson we are going to be looking at the left-hand side menu navigation menu so within the apps script ide they've provided a whole menu here on the left-hand side that allows you to without losing and moving off of your project to open up the right windows and access the content and the information about your file so the default window is the editor window and that's the one that we're currently on there's also an overview window and this will tell you information about when it was created when it was modified the role of the creator the different deployments the executions how many times we've run that users and this before we'd have to go to the main apps script and we'd have to be able to select the script that we want to see but now we've got it all within one place where we can easily just access and we can see if we've run any errors if we have any execution problems and this also helps for debugging we can make a copy of the script in the information area as well so this is really easy where we can make a copy of it we can add a star to it and for the star there's a special slot here within the projects that you can see the starred projects so if you want to add in a star to maybe the one that you're working on or some of the important ones that you've created this is a great way to make a sorting and sort that out from the other projects that you might have so now that i've added into the start project if i refresh i'm going to see this new project within the starred projects there's the project and then it also gives me the overall health and information about the project if i refresh it and if i go out to my google drive you can also see that there has been a star now added into the new project so it is start and as well from the google drive you can select and you can remove the star and you can add the star as well from the google drive so that's one of the options that's really nice to have that you don't have to navigate outside of your script you don't have to change any pages you can do that all nice and neatly within the script and get all of this information and as well you can remove the project so if ever you need to go back to the editor this is going to open up the editor where you've got all of the code that you're updating and editing there's also the triggers on the left hand side mean navigation menu and this will give you all of the triggers that you currently have on your project i don't have any pr triggers on my project but again it's a nice way to add triggers and add triggers add automation to your projects and if you do have a number of triggers you want to be able to sort through them so you can check out and just show using a filter the different triggers let's go ahead and add a quick trigger to the project so selecting a function that we want to run we want to run the test one deployment where where should it run so we're just going to run it within the head there's no other options right now within the select event source so there are two different ways to add triggers either time driven or a calendar event so from the calendar this can select from the user's calendar and we need to make sure we add in whoever the user owner of the calendar is typically we do do time driven events so they're a lot easier to set up and they can run on regular intervals so time driven we can set either from a specific date and time we can set it as a minute timer hour timer day timer week timer or month timer so let's go ahead and set a minute timer how often do we want it to run in the minutes we can run every minute if we want 5 10 15 30. so there's a number of different intervals that we can set and then also for the error notification typically i do set it on notify me immediately but if you don't want to be bombarded if you've got a number of scripts running you might set it to daily weekly hourly so it's up to you depending on how you want the notifications to work you can also update and add in different ways of notifying so it can do it immediately and as well it can have the other options hourly and so on and these are actually really good to have and add in add in the failure notifications because ideally when you do set up a trigger you want to kind of let it run and automatically run so this will give you some peace of mind and in case it's running and you want to be able to make sure that it is running and if it's not running if it throws an error you're going to get the error messages and as well within the triggers you've got the option here where you can open up and reset the parameters of the trigger and then you can update the project details you can see the executions of the trigger you can see the failed executions and the successful ones and as well you can delete the trigger so that's all within the left hand side menu there's also the executions so this is a listing of all of the executions so this is the ones that we've been working on and we've seen uh which ones completed and which ones were cancelled we can get different details so we can view if there's a trigger on it and so on so this one is actually from the trigger so we get information about the trigger execution uh and in this one this one was just the typical execution it kept the execution log so you can always go back to it if you're debugging and if you want to go back and see one of the execution logs from one of the previous executions of the script or the functions you can see that as well in there you can rename it so if you want to track a particular execution and you want it to stand out from the other ones you can rename it and that will rename the project that the execution is being done on you can also open up the project and project details but it already is open here so we don't need to reopen any specif specific windows there's also with the filters so we can check to see what type of execution it was so you can see if it's an add-on automation custom function editor and so on so i'm going to just select the ones that were done with the editor and that's going to only show the ones uh filter out the rest of them and show only the ones that were executed with the editor so again really nice to have and the nice thing about it is if you want to get back to your code you just click the editor option and that's going to bring you back to the editor option and then lastly there's project settings so these are settings that pertain to the entire apps script project so changing of the settings will not impact the existing deployment but if you are creating and creating an add-on you have to update the json manifest here so this is just an option to show it there's also you can enable the chrome v8 runtime you can log uncaught exceptions within the cloud logs if you add in the apps script json manifest for add-ons you do need that when you go back to the editor you're going to see you're going to have the apps script json manifest so right now i don't have a whole lot here within the json manifest but what the json manifest does is if you've got any permissions that you want to set dependencies and so on those can be added in here so going back to the project settings there's also the id of the apps script project so if you ever need the current apps script id you can copy it and then you can also set your google cloud platform so if you are creating an add-on you need to update your gcp so the google cloud platform so you can go here and create a project and then add in that project id here within the google apps script interface here within the google cloud project and add the id there so this is can be done by clicking the change project it walks you through the steps in order to change the project id also to set up the oauth scope after creating the project so there's some more information about how to set and create the add-ons and then once you've created the gcp project number you can set that here and set that as your project number the default of course is just regular apps script and that's not going to include anything for the project so it's just going to be using the regular gcp default project value so try it out check out and create a trigger and also check your executions and any of the triggers make some updates to your trigger and actually i'm going to remove out the trigger because i don't want that to continuously run this is just a testing application check your execution some of your prior executions check out the logs and then also check what you've got within the project settings and you'll be ready to move on to the next lesson where we're going to be looking within the ide and the files libraries services and so on so that's still coming up in the next lesson in this lesson we're going to be looking at libraries and they can be accessed under the files area so to the left of your editor screen you're going to see a listing of files so up top here you can add different files so the files options are another script file so it's another google script file or an html file so creating another google script file we can add that in and it's going to be saved as another gs file and the nice thing about the various files is that you could use them across other files so let's say we have a variable of value of total and we want to use that within the v2 and you also have to make sure that you don't have the same function names so we're not reusing the function name because the scripts are going to be just as you would if you had multiple javascript files that they're going to run one and then the second one so you're going to be actually overwriting this function if you're already using it so we can't have an option for the same function name so let's set this up as my function 100 and then within here we'll use the logger log and we'll output whatever we've got for total so within the log we've got the drop down for the total variable and now let's run this function and we get the output of a thousand so that's how we can create multiple google apps script files the json manifest is the one that's created automatically if you don't want to see it anymore you can uncheck the show manifest and that's going to be now gone from the editor there's also an option to create the html files and html files are typically used as client-side for web apps and it's also some cases you can use them as templates for html templates so number of uses and what this does is this just runs regular client-side code so however you're going to execute this and generate it if you're doing a web app you can include styling and you can also have javascript code as well run in here and then you can include these and use these within your project so i'm not going to type any additional content here but this is just regular html type content and sometimes you can as well generate this so it will start by a default html5 template and you can generate this you know your local editor and copy and paste it within apps script there's also the formatting here so if we do the format of the selection it will for more format it the same way that it does the google apps script that also collapsing the parents so each one of them is self-contained and indented for the new part there's also an option for libraries so if you have a script id that you want to include you can include it as a library in your project and i'll show you how to create a library as well so if we want to create a library we'd have to still deploy it as a library and then lastly there's also services so there's a number of more advanced services that are available so these allow you to access the various google apis so if you are looking to get a little bit more out of what is available within the general google apps script if you want to connect to the google youtube api you can do this and this will allow you to connect to the api and bring the google api into the youtube api into your project uh check the identifier because this is how you can identify it within the google script so now you've got an option for youtube and this brought in the api so we can check to see the various videos we can do a search this is an object so let's select under the list and that's going to be the method that we do the search by uh let's also return back the results in a variable called uh vids and then we output the results into the log of whatever we're getting back from the viz this is one of the advanced scripts so there's more information about it if we go over to the developers advanced area it's got some examples of how to make that selection so when i search under the id the snippet the maximum results i'm going to copy this object information out and we'll just copy it into the script just to save a little bit of time here so under the list method we've got an id and a snippet value that we're providing there's we're going to look for dogs and then we'll loop through and return back each one of the results that are going to be returned back in the items so we run the code we need to review the permissions except permissions for our account as we've added in new options so view your youtube account and it looks like we do have an issue there because we're looking for results and i set the variable name as vids so let's save and run that one more time so that's going to return back all of the found results for the youtube video and the apis are really neat because you can do quite a bit with the apis so we can actually return back the results and use this as one of our library functions so we're going to do that as well in this lesson and then lastly within the services if you ever want need to update the youtube api so whatever one we're using we can make a selection of it we can select which service we want to use and if we open up the services the one that we're currently using is youtube so that's available here if we have to update the version we can easily select and update the drop the version in the drop down so that's available under services so let's go ahead and save this as a library so we'll return back and i'll create this as a function called find vids and it will search whatever we're querying and return back the results and then we'll instead of outputting it we'll return the results results object and then we can use that as a library so what we want to do for the library is make a selection of this function that's going to sit within a new project and i'll call it i'll call it vid and we'll reference this as vid and i'll show you how to do that in the upcoming lesson where we're going to deploy it as a library and then bring it into another apps script project so that's still to come so go ahead and try out the services add in one of the services you can add in youtube do a youtube search and coming up next we're going to look at libraries in more detail this lesson we're going to be looking at deployment and managing the deployment of our google apps script so we've given this app script a name of vid we've created a function within one of the libraries within one of the google script libraries called find vids it's got a parameter here for the query value and it's going to return back all of the results so let's see if we can deploy this as a library so the deploy option is in the top right hand side of your ide and you've got a drop down option for the deployments you've got an option for a new deployment to manage the existing deployments and to create a test deployment since this is our first deployment we're going to create a new deployment within the deployment popup window you've got an option to select the type of deployment so we can set up it as a web app an api executable an add-on or a library in this case we're going to be creating a deployment as a library that we're going to share this library to another google apps script project so within the description let's enter in a description and we'll call it the video finder and hit deploy so this is going to deploy the library the script as a library called video finder within the description and it's going to allow us to share it with others so it issues a deployment id and also issues a url for the library so where it's located so the id can be used within other apps scripts to access that functionality that we've just created within this script now it is suggested that you do try to avoid using libraries on large scale projects as the execution of libraries is going to be slower than the execution of the script that's native within the apps script so it's best to create additional google script files that you would copy and paste into your projects for larger scales projects so this is just for demonstration purposes of how to use the library so go ahead and copy the deployment id and then hit done and under the deploy button now that we've managed and we've created a deployment we can hit manage deployments and it's going to give us a listing of all of the active deployments that we have so we've got a version one deployment the date the time when it was deployed the description of the deployment and here again we can access the id and the library it also gives us some information so we can let other people in groups to use the project as a library and share this project with them so let's uh go ahead and we can cancel and we're going over to the google apps script and we're going to create a brand new script and using google sheets so creating a blank spreadsheet and give this spreadsheet a name i'll call it youtube list under tools hit the tools script editor to open up the ide and this is opening up a brand new ide and we're going to bring in that library into this project and just give it a name call it new proj let's go back to the first script that we've deployed as a library get the id so the unique id that we've got within the web app url and just copy the id out there and then for the library click the plus sign the add library option will pop up paste the id of the library into the script id hit the look up and that will pop up the library information so if you've got different versions you can select the version that you want to run i'm going to run version one and when we deployed it when we go under the manage deployments we only just have the version one so that's corresponding to the library the identifier that we use so this is the identifier and the identifier is how we reference the library within the project so if we want to reference it under v i d we can just use the v id x prefix in order to reference that library so now we've got the library listed on the left hand side under the files and let's create a value for results and using vid library it's going to give us a listing of all of the functions so we've got the find vids and let's look up cats and then under logger log we'll log out the results that were being returned back and that should log out the results content so we'll run the function and let the script execute we need to accept permissions in order to access that script option so accepting permissions and because this is a new app that's running and accessing youtube it's also accessing it via this account so let's uh just provide the permissions so it's accessing the same permissions that we're using within the other project so we did throw an error here and that's because the service has not been enabled on this script because the other script it's just not just running a function it's using the youtube service so you can't actually use the service from this script even though when we were trying it it was working we need to also add the youtube service into the new script where we want to use it and select it add the service and we can close the execution log so now we've got the script and the service added and again typically you wouldn't be using it for something like this where you're just connecting to a service in one script and then accessing it within another so you'd probably be doing something with the search results but again we are trying to demonstrate the library process so that's why we're using it this way and as well with the results we can ignore this message because it's got an error here but it doesn't see that there is a callback for this function so that's why it's throwing the error there so let's run the my function and now we're getting the all of the content coming back from the api it's actually coming back as fairly large a number of different results that are being returned back so we can also fine-tune what were returned back so if we only want just the items as an object we can update that script and we have to redeploy it so have a new deployment as we're having a new version of this library and we'll just call it our version two of the library and now going back into where we're executing the code under the libraries let's uh select this library so open it in a new tab it gives us information about what's contained within the library and the library itself we can update the version and let's just double check the manage the deployments and we'll run the function one more time so this time we're just returning back the different objects and each one of these objects they contain an id and they contain a title so if we want to output the information that's contained within the object we can break that apart as well and one of these objects appears to have quite a bit of content there attached to it go back to the vid script and we're going to upgrade update the value of total to 5000 and then run through the my function again and we're still sitting at value of 1000 so we're not using the newer version of the script uh let's uh click it again and it doesn't look like we've gotten the versions so removing the library and then let's select the id again and we'll add in the new library and this time we should be able to see the version so sometimes it does take a while for the script to update and do a quick lookup and now we do have the version let's do another deployment so manage the deployments and do a deployment of it in the library paste the script id do a lookup so it looks like we don't have access to the latest version so let's just select the head development and that latest version will show up so again it does take a little bit of time so we're logging out the results let's just check to make sure we've got an updated value for total and that the results are being returned back as just all of the different results for the content so it's being output there now let's add it into a spreadsheet so select for the spreadsheet object selecting the spreadsheet app and getting an active spreadsheet object and then let's get the sheet we can select the sheet by name so if we want to list out all of the youtube stuff and select set the name so selecting the name youtube so it's going to select the sheet object for us to use i'll actually just rename this to sheet and then within the sheet itself we can append a row in the suspecting the data that we want to append with so let's loop through results using four each and each one of the elements that gets returned back we're also going to pick up the index value and then return this back within a function and this is where we're going to append the row of each one of the results and let's uh append the row with the element content and we can also log out each one of the elements and see what we've got for the results so let's do a run of that we need to accept the permissions because now we're accessing the spreadsheet object and writing into the spreadsheet so also accessing the youtube so as it runs through it's going to be now listing it out all within a json format and if we want to break this back into a usable object we can take the element and turn it into a javascript object by using jsonparse of the element object and let's take a closer look and see what we've got here so if we want to just return back the title and also if we want the so we can get the snippet information and that's contained within contains the title so selecting the js object snippet and title and save that and i'll comment out the results and we'll only have the ones that we're outputting as we're looping through and make this smaller so now that's how you can get all of the titles and dynamically added into a spreadsheet so whatever the content is that we're searching for and this is coming in from the other project that we've created where we've got the other apps script and we're using that as a library and bringing the content into our spreadsheet within a new project and within the deploy you can also update and manage the deployments you can test the deployments so we've got test deployments for web app api executable and google workspace add-on so if you want to test those if you want to manage the existing deployments it will give you all of the deployments so the archived ones in the video finder so these were the ones that were archived if you want to redeploy an older one you can select the deploy and then that's going to redeploy one of the older projects that we have or older deployments that we have and you can always create new deployments as well and then within the library you want to make sure that you're using the latest version so you can always click that and select the version that you want to use so now we've got all three versions there right now we're just using the development mode so the head version but now we've got the version three there so that was the latest one so it does take a little bit of time to show up as one of the library versions when you make the updates uh so usually give it like five ten minutes and it should show up within the library drop down version option so try it out uh create a file a google apps script file as a library and then bring the library information and make use of it in another google apps script project and you could be ready to move on to the next lesson this lesson we're going to be deploying a web app so web app uses a default function and that function name is going to be do get and what do get does is this outputs the content into the web app so the web app will automatically look for this function and output any content that's related to it there's a number of ways to output so two different services that you can use and these are the google script services there's the content class the class text output class and as well as the html class the text output just creates from the content service text output and what you do is you return content within the do get you can also set this up as a variable and this will just be regular string content that's being output so if you want to return back hello world we can do that and just whatever hello world content that we want to have and then using the content service let's create text output and the text output that we're creating is a string and once again you do see within the pop-up that it does have the reference and it tells you what parameters are being expected within the parentheses so whenever you start with the parentheses it'll give you an example and what create text output does it creates a new text output using do get here it's creating content service output and you're appending the html and then returning it so this is structured slightly different but it's doing the same thing where we've got an output service that we're returning and then we're adding in some content into that so you can add it within here or you can just append it as content that you're outputting so there's two options for this method there's some more information here how to create it so this is another example of how it's being used and this is more in line with what our code structure is where we've just got the string value within the create text output so let's add in the string value into the create output and save it and now deploy it as a web app so go into the new deployment and select type so select the web app type and i'll just call it test it's going to ask you a few questions so execute the web app as so this is important because if you're executing that web app and the default is to execute it as the current account that's creating the apps script you can also get it to access the web app as the user that's accessing the web app and then they're going to be asked to log in and authenticate the app so providing the permissions on their account so in some cases you might want to try to avoid this just to make it easier for others to use and if you are accessing something like sheets since this project isn't accessing sheets but if you're accessing any of your documents on your drive that user that's accessing it via the web app is going to also have to have permissions to those so it makes it a little bit more complicated when you get it to execute as the user if you're just outputting regular text as we're doing it in this example that's fine for them to access but if we're accessing additional content within the drive then it becomes more complicated because they do need to have the permissions set also who has access so you can set it up as yourself so if you go to the web url you're the only one that can see the content in the web url anyone with a google account so that means that if they're logged into your google account if you're part of an organization within g suite organizational unit that's going to be a fourth option that you're going to have here to only allow people within the organization and then anyone just creates an open web app url so this means that anyone that you share this url to they don't have to log in they can simply go to this web app and see the content it's got the copy of the content of the web app so you can copy the web url or you could just simply click it and see the executable content so it's being output as hello world and done and now we can see the manage the deployments so within the deployments we've got an active one and this active one is going to be the web app you can pick up the web url here once again and there's also a dev version so when you're developing a web app you can go under the test deployments and for the web app that's going to give you a developer version and the difference between the developer and the executable is at the end it's going to be dev whereas executable is ex ec and the devel the dev version is the one that if you make any changes to the code you're going to see the changes of the code so that's the dev version and then this is the executable version and as well the dev version it needs to be can only be accessed by users that have shared editing permissions to the app so if they don't have shared editing permissions they're not able to see the dev version so they're not going to see anything being executed out another option that you have as well and this one's a more robust option is to output html content and that also uses do get so i'll just rename this to old let's create a new function do get and create a web app so the idea is the same that you've got some content uh so let's create some html content and you can include any type of client-side code here as needed uh so we've got html hello world we're outputting and then return back using the html service let's create html output and now it's expecting a string value of output that's being returned so content to serve up and of course it does have the examples here of how to output the html content and now let's run the dev version and we've got the extension for dev there so on the html service uh the you the web url is going to be different because it's going to redirect to the output the html service output whereas the content is just outputting as an uh as a macro that's being output directly within the browser so there's no redirect and there's no wrapping of the application container because this is just regular text that's being output whereas this has the ability to run javascript and styling so it allows it to run code within the browser so that's why it's wrapped within the google application dev environment as well as executable environment you can also execute and output content from a template so that's another option so doing the return and we do have this html template here so using the html service let's create output from a file and the file that we're using it's expecting a string value for the file name and we don't have to include the html we can just include index so going back into the dev the content that we've got output and now this is actually coming from the file so if we were to add in any style information we can add that as well here and set some properties and background color of red so let's refresh so there's our dev background color of red let's deploy this web app create a new version this is our new and improved version with the red background and let's uh refresh the executable url and now it's outputting the html so we've got the wrapper for uh the html service we've got it as executable so that's the executable one that you'd share with others and the dev one is the one that you update and you can check out and debug as you're developing the web app so go ahead try it out say and create the web app output content html as well as using the create text output service and you'll be ready to move on to the next lesson in this lesson we're going to be going over some of the powerful features that are available with the apps script ide so one of them and some of them we've seen that they pop up let's take a closer look at some of the features so creating a variable name so this one's going to be rather long and i'm going to use it in a few places within the code and then we'll make an update of the name of this value so let's just type in a string value here that we're going to access within the code and then make use of this function or this variable value in over here as well as within the my function so a number of places that we're going to be using the code and i'll make it messy and then we'll clean up the code as well using the editor so using the format of the document so it's going to remove out all of and also indent that properly so unfortunately it doesn't remove out the duplicate lines so that's not an option yet within the editor but you do have the option to make selections and update some of the code and values so let's make an update of this variable and this is one of the things that is really super useful with the new editor that we can make a selection of a variable name and we can go to the symbol so that will provide the symbol here and show you that it's been registered we can also change uh rename the symbol so this allows us to rename the symbol and i'll just call it new name and press enter and we see that it's been actually renamed in all the instances wherever it's being used so this saves us of having to do a find and replace of an update and if we do want to do a find and replace of let's say some words so select the content and then you can either right click control click or use the f1 for the command palette so it's going to come up and we've got an option with replace it's also got a shortcut for this replace so if you want to take every instance of hello and make a replace to goodbye we have an option here as well to match whole word uh match the case and then there's also a regular expression that we can enter in so there's a few options that we can do the replacement it tells us how many it's found how many instances of it so two out of three we can also replace and we can replace all so we can go down to the previous one that it's found go down to the next one go down to the next one and again back to the previous one so if you want to just replace all of them we can do a replace all and now we've got no results that are found so the command palette has given us quite a few options now with editing and finding and doing a replace if we want to see where a function is being used again we can either do a control or right click and check to see where we go to references and there's also the peak references so that pops up the window where we can see every time that the my function has been used to see it's been used twice so there's two references to the word my function uh we can also go to the references so it's gonna also have the pop-up window and it's gonna allow us to move and navigate to the various references of this function and again within the command palette so that's all either the f1 so we can add the cursor above at the cursor below it's got the keyboard shortcuts for the cursors there's the main command palette option so that's this one that we're looking at right now it just provides you the shortcut typical stuff like copy copy line down copy line up cursor redo so those are the same as we have up here where we can redo we can delete all and shortcuts for doing the deletes so helps us to write the code better there's also duplicate the selection so it's a really quick way to do a copy and paste of our current selection you can delete lines we can expand the selection so it's contracting and spanning the selection we can find we can find next these are also done with shortcuts they got the shortcut options and as you learn and as you work more with google apps script and you become more familiar with the shortcuts i do encourage that you do try out the shortcuts because it really does make the coding to be able to code quite a bit quicker uh format of document is there go to the bracket go to definition so that's the one that's going to provide the definition and the command palette is the one that has all of the best functionality that the advanced functionality so you can go so go to the different problems so as you're debugging you can move through them finding the references finding the symbols so what we've just done going to the next line and if you're debugging this is a quick way to move through the debugging and we can insert lines we can replace the symbols we can refactor it and you can do all of this with the command panel as well as you can do with the keyboard shortcuts and there's also the transform to lowercase title case and uppercase we can change the hints so trigger parameter hints trigger suggest so you can turn those off and on so providing the suggest triggering the suggests so selecting and if you're not seeing the suggestion you can get a trigger and see all the different suggestions that are available and you can also use of course the shortcut for that there's also uh unfold unfold all transposed letters show definition preview hover so that's the one that whenever we hover over it you can also toggle options and if you want to do a search if you would just want to look for what you've got for toggle you can toggle a block comment so that provides you the block comment there if you've made a selection you want to comment out some of your code you can do a toggle of the block comment let's type in the toggle and there's also the shortcut for that so it allows you to toggle blocks of code quickly and then you could also untoggle it the same way also under the command palette let's also check out some other toggle so we can toggle the fold and we don't have anything folded so let's fold some content and select from the toggle we can unfold all so that will open up all of them again going back into the command palette there's also a toggle high contrast theme so if you prefer to have a black background with light text you can do that as well or you can have a high contrast theme uh if you want to toggle it back you can select and toggle the high contrast theme there's also the toggling of the line comments so the toggle stuff is allows you to customize how you've got the output of the content and how it's going to look tab menu focus as well so there's toggling of that and there's just quite a lot of options here that you can really optimize how you're writing your code and editing debugging the content of your code and that wasn't available within the legacy editor so this is all available within the new editor so try out some of the functions within the command palette to get more familiar with what's available within the apps script ide and i do suggest that you as well try it out as the shortcuts as you become more accustomed to writing google apps script so as you write more code there's you're going to realize that there's so much stuff that you can do go back over to the documentation try out some of the samples the different google apps script samples to check out all of the wonderful functionality that google apps script provides so these are common things that common apps to help improve productivity and do some automation within your google suite of services so check out what's available avail at the github google workspace try out some of the code that's here and you can even customize it to make it your own if you have any questions or comments i'm always happy to hear from you thanks again for taking this section and learning more about google apps script
Info
Channel: Laurence Svekis
Views: 27,851
Rating: undefined out of 5
Keywords: Laurence Svekis, Svekis, Courses, Udemy, Learning, Coding, Learn code, JavaScript, HTML, CSS, JS code, Code example, elearning, Learn to code, how to code, learn web, web design, web development, application development, coding course, online course, responsive design, modern web design
Id: UIfslpbVu_U
Channel Id: undefined
Length: 114min 54sec (6894 seconds)
Published: Sun Dec 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.