AI Workflow Automation

How To Connect AI Workflow Automation to Google Sheets

Google Sheets as your WordPress Database

Google Sheets integration is a highly sought-after feature in workflow automation. While we’re working on developing a robust, native integration for our AI Workflow Automation plugin, we want to provide you with effective methods to connect your workflow triggers and outputs to Google Sheets. This guide will walk you through two key processes: setting up Google Sheets as a trigger for your workflows and using webhooks to save workflow outputs to your sheets.

Part 1: Setting Up Google Sheets as a Workflow Trigger

Follow these steps to configure Google Sheets to trigger your AI Workflow Automation:

Let’s assume that you have already designed your workflow in AI Workflow Automation plugin. You need to set your Trigger node type to Webhook. When you do this, the node will automatically generate a webhook link for you. Copy this link as we would use it later.

image of the webhook trigger

1- Prepare Your Google Sheet

Open an existing Google Sheet or create a new one.

Navigate to the “Extensions” menu and select “Apps Script”.

2- Configure the Apps Script

In the Apps Script editor (a file called Code.gs), replace the existing function with the following code (just copy it):

function editRow(e){
  if(e.changeType=="EDIT" || e.changeType=="INSERT_ROW"){ //The type of change (EDIT, INSERT_ROW, INSERT_COLUMN, REMOVE_ROW, REMOVE_COLUMN, INSERT_GRID, REMOVE_GRID, FORMAT, or OTHER)
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); //get activated Spreadsheet
    var sheet = spreadsheet.getSheetByName("YOURSHEETNAME"); //get sheet by sheet name
    var headings = sheet.getDataRange().offset(0, 0, 1).getValues()[0]; //get heading
    var column_to_watch = 3; //A=1, B=2, C=3 etc...
    
    var row = sheet.getActiveRange().getRow();
    var column = sheet.getActiveRange().getColumn();
    
    if (e.changeType=="EDIT" && column != column_to_watch)
      return;
    
    var values = sheet.getSheetValues(
        row, // starting row
        1, // starting column
        1, // number of rows
        4 // number of columns
    );
    
    var payload ={}
    
    for (i = 0; i < headings.length; i++) {
      var name = headings[i];
      var value = values[0][i];
      payload[name] = value;
    }
    payload["row_number"] = row;
    
    var options = {
        'method': 'post',
        'contentType': 'application/json',
        'payload': JSON.stringify(payload)
    };
    UrlFetchApp.fetch('yourwebhookurl', options);
  }
}

It should look like this:

3- Configure the Script

4- Setup the Trigger

You will now be asked to approve this trigger using normal Oauth, choose the correct Google account and approve.

And that’s it!

Now when your selected action happens you can get your data in your AI Workflow Automation plugin.

The Webhook Trigger in your workflow has a function with a button called get samples. This function will automatically identify the structure of the data being received from the webhook. In the case of Google Sheets, your first row represents your data headers.

If you click on get samples, and go back to your sheets and add a new row (or whatever action that you chose) then you should receive your data structure in your trigger node immediately. You can then use each of these data sources separately in the subsequent nodes. It would look like this:

Part 2: Saving Workflow Outputs to Google Sheets

For this process, we’ll utilize a pre-existing add-on from the Google Workspace Marketplace:

1- Install the Add-on

2- Configure Your Workflow

And that’s it!

Conclusion

By following this guide, you’ve successfully integrated Google Sheets with your AI Workflow Automation processes. This setup allows you to trigger workflows based on sheet changes and save workflow outputs directly to your Google Sheets, enhancing your automation capabilities.

While we continue to develop a more streamlined, native integration, these methods provide a robust solution for leveraging the power of Google Sheets in your workflows. As always, we’re committed to improving our plugin and welcome your feedback on this integration process.

Remember, the flexibility of AI Workflow Automation combined with the ubiquity of Google Sheets opens up a world of possibilities for your data management and automation needs. We encourage you to explore these capabilities and discover how they can optimize your workflows.

Exit mobile version