Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 876
Fajarmf Avatar asked Feb 14 '23 19:02

Fajarmf


1 Answers

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.

like image 183
Serge insas Avatar answered Mar 23 '23 11:03

Serge insas