r/GoogleAppsScript • • Mar 01 '24

Question Thoughts on the current best stack for simple small business apps

Hello! I have been building simple apps with Apps Script for one client going back to 2017. What started as a few API requests to add new rows in Sheets has ballooned to 16 Apps Script projects across dozens of Sheets, Forms, custom UIs, and automated emails. While much of this functionality works well, there are some significant downsides and I’d like to hear feedback from this community on better approaches.

The current stack I use is:

  • Develop locally with vanilla JS and Prettier.

  • Push commits to Github and then sync changes via the Google Apps Script GitHub Assistant Chrome Extension.

  • A combination of triggers, menu functions, and custom UIs for the clients employees to invoke various business logic (import data, create invoices, generate documents, send emails, etc).

  • Most of the day to day work by the client employees is done in Sheets, Drive, and Forms.

Things I like about this current stack:

  • I don’t have to build and maintain any UIs. With the exception of a little HTML/CSS for emails and custom sidebars/modals, all the UIs the client uses daily Just Work.

  • Very easy to integrate with Mail, Drive, and everything in the Google ecosystem.

  • Good documentation and forums.

  • I have pretty good results running integration tests where I write a method that grabs the current data in a Spreadsheet or Sheet and then makes assertions about the expected schema/values. I run these data consistency tests via triggers and any failure sends an error email.

  • My clients' employees are pretty comfortable with Excel/Sheets so they can self service a lot of desired functionality using formulas in Sheets.

Downsides to current stack:

  • No unit testing.

  • No Typescript.

  • The Chrome Extension is a clunky way to deploy. I’d rather use something like Clasp and/or Github Actions.

  • Using Sheets as a data store has been quite slow for many business functions. Some of the projects are working with Spreadsheets that have tens of thousands of rows across dozens of Sheets. All of the reads and writes really slow down the human user experience especially when the client adds a bunch of array formulas and vlookups.

  • I’m also worried about read/write/delete conflicts with Sheets as a data store. I’m using LockService where I can, but it doesn’t seem nearly as safe as a proper relational database.

Questions:

  • Can I stay in the Google ecosystem but use a much faster/reliable data store that still provides Excel/Sheets like self service? If I move the data store to Google Tables or Firebase how easy would it be for the client to access data in Sheets?

  • What templates and tools provide the best foundation for a greenfield Apps Script project? I’m thinking about trying ez-clasp for my next new project.

7 Upvotes

18 comments sorted by

5

u/marsili95 Mar 01 '24

Looks like Big Query is the way to go for you. It is really easy to integrate with apps script and it offers a really nice free tier.

Let me know if you want to try it and I can give you some code to understand how to use it.

1

u/jjrides Mar 02 '24

Thanks for the suggestion! At first glance BigQuery looks great. It is a much more robust data store, has an Apps Script class for easy access, and can easily be synced to Sheets for easy human user views.

3

u/marsili95 Mar 01 '24

Yeah sure! Here you guys have some really simple code to add new rows to a BigQuery table. Of course, you will need to map the sheet data to the required dataObject format.

function addNewData() {
  
  const projectId = 'your-project-id'; 
  const datasetId = 'your-dataset-id'; 
  const tableId = 'your-table-id'; 

  const dataObjects = [
    {
      column1: "value1_row1",
      column2: "value2_row1",
      column3: "value3_row1"
    },
    {
      column1: "value1_row2",
      column2: "value2_row2",
      column3: "value3_row2"
    }
  ];

  addMultipleDataRows(dataObjects, datasetId, tableId, projectId);

}

/**
 * Adds multiple new rows to a specified BigQuery table.
 * 
 * @param {Array} dataObjects Array of data objects to be inserted into the BigQuery table.
 * @param {string} datasetId The ID of the dataset containing the target BigQuery table.
 * @param {string} tableId The ID of the target BigQuery table.
 * @param {string} projectId The ID of the Google Cloud project containing the BigQuery dataset and table.
 */
function addMultipleDataRows(dataObjects, datasetId, tableId, projectId) {
  var request = {
    "rows": dataObjects.map(dataObject => ({
      "json": dataObject
    }))
  };

  try {
    const response = BigQuery.Tabledata.insertAll(request, projectId, datasetId, tableId);
    if ('insertErrors' in response) {
      response.insertErrors.forEach(error => {
        console.log(error.errors);
      });
    } else {
      console.log("Data inserted successfully :)");
    }
  } catch (error) {
    console.error('Error inserting data:', error.toString());
  }
}

If you need to access this data, the easiest way is by conecting the bigquery table to a sheet. This link explains how to do it:

https://support.google.com/docs/answer/9702507?hl=en

2

u/leob0505 Mar 01 '24

Hey, I'm not OP but I'm interested. Could you share some code samples with me?

1

u/jimapp Mar 01 '24

And meeeeeeeee! Thanks :)

1

u/jclthehulkbuster Mar 01 '24

Same here I would like to learn a bit more about it Especially as I have data coming in via csv that includes previous entries with updated information.

Not quite Sure how to integrate it in correctly

4

u/[deleted] Mar 01 '24

Have you tried out Appsheet? Pretty easy to make relational databases and user interface is pretty easy to interact with for the client

1

u/jjrides Mar 01 '24

Thanks for the reply. I have looked at AppSheet briefly, but I'm not sure if it provides enough granular control. For instance, can I write I custom script (or use a combination of "Actions" and custom scripts) that will:

  1. accept user input,

  2. make a series of API requests based on business logic, then

  3. insert or update rows across multiple tables?

1

u/marcnotmark925 Mar 01 '24

Yes you could accomplish that.

1

u/jjrides Mar 02 '24

How would you insert or update rows in an AppSheet database?

0

u/marcnotmark925 Mar 02 '24

The same way you'd add or edit records in any other table.

1

u/byssh Mar 02 '24

You’re more advanced than me on just about everything, but AppSheet does allow you to create automations (they call them Bots) that call Apps Scripts. I’ve made a few apps that use a copy/paste specific row that proc on user action. I might be wrong, but I think they can call APIs as well. AppSheet also connects to other relational dbs, BigQuery for sure.

1

u/jjrides Mar 02 '24

Thanks for the advice. I see how to invoke an Apps Script from AppSheets, but it is not clear to me how an Apps Script would then add/update/or delete data in AppSheet. Many Google services have an App Script class that allows easy access to that service (example docs), but it doesn't seem like AppSheet is a first class service in App Scripts. So I'm guessing that in order to add/update/delete data in AppSheet using Apps Script I would first have to modify a data store somewhere else (like Sheets) and then have the AppSheet sync that data.

2

u/byssh Mar 02 '24

Right. The entire concept of AppSheet is that it is built off a Sheets, but I know it can connect to BQ. That’s not something I know anything about because I haven’t had a reason to yet, tbh. AppSheet also supports its own relational db. Your use case just sounds similar to mine, with a whole lot more data. It may be worth looking into the other data connectors in your case.

1

u/jjrides Mar 02 '24

Ok, that is helpful context. It seems like AppSheet isn't meant to be its own data store but rather to import or sync to other data stores. The primary value with AppSheet seems to be the no code (or light coding with linked Apps Scripts) easy Actions/Bots that allow a non-developer to create functionality.

I may use AppSheet for some future project, but for the client I have in mind, the lack of an API (or class) within Apps Script is a deal breaker.

2

u/byssh Mar 02 '24

Not only do I understand; I massively appreciate your civil and reasoned explanation. I hope you find a solution that works for you then. :)

1

u/fugazi56 Mar 01 '24

Love this topic. I could use your help with our Workplace stack. I sent you a DM.