2

Can I have two different doGet() functions in one Google Apps Script project? I'd save them in two .gs files. If it's possible, how do I publish the web apps separately?

Finn Smith
  • 772
  • 2
  • 7
  • 21

2 Answers2

2

You can make a second project attached to the same document by going to File > New > Project in the script editor. Putting doGet() functions in two separate .gs files is the same as putting two doGet() functions in the same .gs file as far as the compiler is concerned.

John
  • 916
  • 7
  • 14
  • Thanks, that's what I suspected. They aren't attached to specific documents, so it's not that big of a deal. Just a bit messy, in my opinion. – Finn Smith Dec 07 '14 at 01:20
-1

You can have multiple pages served by the one doGet() function.

See Linking to another HTML page in Google Apps Script for an example with two html pages.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • But that wouldn't allow me to create two separate web apps with separate URLs, right? I'm making two different forms using HtmlService that will be accessed by different users. – Finn Smith Dec 07 '14 at 01:30
  • If you want to provide people with the long URLs, no. But if you plan to give out shortened URLs, e.g. using goo.gl, then each form would have its own unique shortened URL (...which would feed the required parameter to your doGet() ). The pro of this approach is that related code would be in one project for easy maintenance. If you do decide to go with separate projects for the different forms, you can make them minimalist scripts, and still put the common code in one project as a "library" for them. – Mogsdad Dec 07 '14 at 02:12