jjones312
jjones312

Reputation: 695

google apps script functions best practtice

I'm trying to teach myself Google Apps SCript and javascript, so forgive if a stupid question. I'm basically interested in learning for business automation of basic workflows etc.. Approval process / mail merge etc. I've seen the examples in Developers page for GAs and other youtube demonstrating how to do this type of scripts. I've had some success in creating a workflow with mail merge, document creation..

What I'm curious is the proper or best practice in developing these types of workflows and use of Functions. The above workflow is one large function with a doGet() to generate a HTML page.

Would it be consider better to break the large function, which onFormSubmit, creates a template, reads data from a forum submitted spreadsheet, writes into a the template replacing %keys%, create a document and attaches to email, deletes document and sends email, in to multiple smaller functions. One for each action i.e create a template or send email etc etc. Then just have the functions call each other by passing parameters??

What is considered proper or best practice / approach for workflows like this??

Upvotes: 0

Views: 417

Answers (1)

user1783229
user1783229

Reputation: 193

I think I generally went down the same trail as you. I started trying to automate everything in a big script but then discovered Libraries https://developers.google.com/apps-script/guide_libraries. So now I have a MyUtilities library with a bunch of mini functions which normally get run over and over and just call them from a few main functions when needed.

I don't know if it's a best practice per se, but it makes the main functions leaner and easier for me and I can use MyUtilities in any main function. I have things like searching for a column number based on a column name so those functions aren't dependent on a specific row number, because you know they can change as workflow changes - and I can call it from any main function by passing the parameters. Works for me.

Upvotes: 1

Related Questions