Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a file into your project

I'm creating a Google Apps Script that's kind of a quiz marker / email merger in one. I've got everything working but my code is pretty long because I find myself having to use procedural coding. This is mostly because I don't know how to use the editor to include a class / library.

I've viewed the Crash Course Video by Kalyan on using the Script Editor, but it didn't answer my question. I've also scoured the internet with no luck.

If you look in the top left of this screenshot, you'll see I have Code.gs and test.gs:

screenshot

I have all my code in the Code.gs file, but I want to include test.gs in Code.gs. Once I figure out how to do that, I'd like to create a couple of simple classes to organize my functions a bit better (and possibly re-use my classes later).

Thanks in advance!

like image 897
Makonnen Avatar asked Nov 17 '13 08:11

Makonnen


People also ask

How do I add files to a project folder?

In the Project tab, click the folder name, and then select Project > Add Files. Alternatively, right-click the folder name and choose Add Files. A file selection window opens.

How do I add a file to a project VS?

You can add existing files to your project by right-clicking on the Project node and selecting Add > Add Files.... Alternatively, to add an entire folder, select Add > Add Existing Folder.... The file browser is shown. It lets you search your system for the required item to add.

Can you attach files in Microsoft project?

Today I will show you how to attach document or link into Task with Microsoft Project for the Web! As you can see I can attach file from my computer, or from Team files, or I can add a link. So, for each Task I can have many attachments, and they can be same or different type! Great feature!


1 Answers

To clarify Zig Mandel's answer and add to it:

  • All .gs files that are located in the same Script Project have global access to each other. That is to say that a function that you define in test.gs is accessible by Code.gs if they are in the same Script Project

  • You can create your own library of code. To do this you would simply create another Script Project, then go to Resources -> Manage libraries..., and add the project key of your original project (that contains the Code.gs and test.gs files). The project key is located in File -> Project properties.

The second bullet point is a good way to organize your code. If you have the same code that you are reusing throughout many Script Projects, then you want to put those functions into one Script Project and create a library out of them, as I explained above.

like image 70
Chris Cirefice Avatar answered Nov 16 '22 01:11

Chris Cirefice