Fajarmf
Fajarmf

Reputation: 2273

Google app script - move some functions into separate files

Is there a way to move some functions into separate files in google app script? currently my Code.gs looks like the following:

function onSubmit(e) {}

function readSpreadsheet(sheet) {}
function writeSpreadsheet(sheet, data) {}

function sendEmail() {}

function helperLogic1() {}
function helperLogic2() {}
function helperLogic3() {}
function helperLogic4() {}

So to make my code looks nicer ;p .. I want to move functions related to spreadsheet to spreadsheet.gs email to email.gs etc. So after moving them, how do I load it from the code.gs?

Thanks

Upvotes: 7

Views: 3205

Answers (1)

Serge insas
Serge insas

Reputation: 46822

You can move any function to any script file inside the same project without restriction, it is indeed easier to read when you split the code in different categories when the code is long.

When you execute any of these function it behaves as if all of them where in the same .gs file. The project is the real container, not the file.

Upvotes: 10

Related Questions