Trigger a workflow from Google Sheets  |  Workflows  |  Google Cloud (2024)

Stay organized with collections Save and categorize content based on your preferences.

Google Sheets is a cloud-basedspreadsheet solution that supports real-time collaboration and provides tools tovisualize, process, and communicate data.

This tutorial demonstrates how to trigger Workflows fromSheets.

Objectives

In this tutorial, you will:

  1. Use Google Forms, a cloud-basedquestionnaire and survey solution, to create a form that can submit requests tocreate virtual machine (VM) instances.
  2. Link a Google Sheets spreadsheet to the form to collect and save anyresponses.
  3. Use Google Apps Script, acloud-based JavaScript platform that lets you programmatically create, read,and edit Google Workspace products, to trigger a workflow whenever a requestis approved through an update to the spreadsheet.
  4. Deploy a workflow that calls theCompute Engine API connectorand creates a Compute Engine VM instance based on the specificationscollected through the form. Connectors simplify the calling of other Google CloudAPIs. Learn more about Workflows connectors.
  5. Test the entire process and confirm that a VM instance is created as expected.

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator. New Google Cloud users might be eligible for a free trial.

The tutorial also uses Google Workspace.Business-grade services that are not included with Google's free consumer appsare billable.

Before you begin

You can run some of the following commands in the Google Cloud console, or byusing the Google Cloud CLI in either your terminal or Cloud Shell.

Security constraints defined by your organization might prevent you from completing the following steps. For troubleshooting information, see Develop applications in a constrained Google Cloud environment.

Console

  1. In the Google Cloud console, on the project selector page, select orcreate a Google Cloud project.

    Go to project selector

  2. Make sure that billing is enabled for your Google Cloud project. Learn how tocheck if billing is enabled on a project.

  3. Enable the Compute Engine and Workflows APIs.

    Enable the APIs

  4. Make note of theCompute Engine default service accountas you will associate it with the workflow in this tutorial for testingpurposes. New projects that have enabled the Compute Engine APIhave this service account created with the IAM basicEditor role, and with the following email format:

    PROJECT_NUMBER-compute@developer.gserviceaccount.com

    You can find your project number on theWelcomepage of the Google Cloud console.

    For production environments, we strongly recommendcreating a new service account andgranting it one or more IAM roles that contain theminimum permissions requiredand follow the principle ofleast privilege.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. Make sure that billing is enabled for your Google Cloud project.Learn how tocheck if billing is enabled on a project.

  3. Enable the Compute Engine and Workflows APIs.

    gcloud services enable \ compute.googleapis.com \ workflows.googleapis.com
  4. Make note of theCompute Engine default service accountas you will associate it with the workflow in this tutorial for testingpurposes. New projects that have enabled the Compute Engine APIhave this service account created with the IAM basicEditor role, and with the following email format:

    PROJECT_NUMBER-compute@developer.gserviceaccount.com

    You can retrieve your project number:

    gcloud projects describe PROJECT_ID

    For production environments, we strongly recommendcreating a new service account andgranting it one or more IAM roles that contain theminimum permissions requiredand follow the principle ofleast privilege.

Create a form to request VM instances

Create a form that can be used to submit a request to create aCompute Engine virtual machine (VM) instance. By default, when youcreate a form through Google Forms, it's saved inGoogle Drive.

  1. Go to forms.google.com.
  2. Click Blank Trigger a workflow from Google Sheets | Workflows | Google Cloud (3).

    A new form opens.

  3. Create a form with five required sections. The form should appear similar to the following:

    View sample form

    Trigger a workflow from Google Sheets | Workflows | Google Cloud (4)
    Machine name

    Short answer text

    Zone

    Dropdown:

    1. us-central1-a
    2. us-central1-b
    3. us-central1-c
    4. us-central1-f
    Type

    Dropdown:

    1. e2-micro
    2. e2-small
    3. e2-medium
    4. e2-standard-2
    5. e2-standard-4
    Disk size (GB)

    Short answer text

    Operating system

    Dropdown:

    1. debian-10
    2. centos-stream-9
    3. cos-93-lts
    4. cos-97-lts
  4. Enable email collection to record the email addresses of people who fill in your form:
    1. Click Settings.
    2. Expand the Responses section.
    3. Click the Collect email addresses toggle.

Link a spreadsheet to your form

After you have created a form, link a spreadsheet to it so that you can saveyour form responses in that spreadsheet. The spreadsheet is saved inDrive.

  1. Open your form in Forms.
  2. Click Responses.
  3. Click Link to Sheets.
  4. In the Select destination for responses dialog, select Create a newspreadsheet.
  5. Click Create.

    The linked spreadsheet opens.

  6. In column H, add an Approved? heading.

  7. Place your cursor in the first row of column H and selectInsert > Checkbox.

    The spreadsheet should appear similar to the following:

    Trigger a workflow from Google Sheets | Workflows | Google Cloud (5)

    Each time the sheet is updated with a response, the checkbox will also appearin the row for that response.

Extend Google Sheets using Apps Script

Apps Script lets you programmatically create, read, and editSheets. Most scripts designed for Sheets manipulatearrays to interact with the cells, rows, and columns in a spreadsheet. For anintroduction to using Apps Script with Sheets, seethe Custom function quickstart.

  1. Create an Apps Script project from Sheets:

    1. Open your Sheets spreadsheet.
    2. Select Extensions > Apps Script.
    3. In the script editor, click Untitled project.
    4. Give your project a name and click Rename.

    Your script is now bound to your spreadsheet,which gives the script abilities to alter the user interface orrespond when the spreadsheet is opened.

    A script project represents a collection of Apps Scriptfiles and resources. Code files in a script project have a .gsextension.

  2. You can use Apps Script to write custom functions that youcan use in Sheets just like a built-in function. Custom functions arecreated using standard JavaScript. Create a function:

    1. Open your Apps Script project.
    2. Click Editor code.
    3. A script file appears as a project file named Code.gs. To edit the file,select it.
    4. Replace any code in the script editor with the following code which readsthe data in your spreadsheet and passes it along as input to a workflowexecution:

      const PROJECT_ID = "your-project-id";const REGION = "us-central1";const WORKFLOW = "create-vm-from-form";function handleEdit(e) { var range = e.range.getA1Notation(); var sheet = e.source; if (range.length > 1 && range[0] === 'H') { if (e.value == "TRUE") { Logger.log("Approved checkbox: true"); var row = range.slice(1) var email = sheet.getRange('B' + row).getCell(1, 1).getValue() var vmName = sheet.getRange('c' + row).getCell(1, 1).getValue() var zone = sheet.getRange('D' + row).getCell(1, 1).getValue() var machineType = sheet.getRange('E' + row).getCell(1, 1).getValue() var diskSize = sheet.getRange('F' + row).getCell(1, 1).getValue() var imageFamily = sheet.getRange('G' + row).getCell(1, 1).getValue() var imageProject = imageFamily.substring(0, imageFamily.indexOf('-')) + "-cloud" const executionPayload = { "argument": "{\"diskSize\": \"" + diskSize + "\", \"email\": \"" + email + "\", \"imageFamily\": \"" + imageFamily + "\", \"imageProject\": \"" + imageProject + "\", \"machineType\": \"" + machineType + "\", \"vmName\": \"" + vmName + "\", \"zone\": \"" + zone + "\"}" }; approve(executionPayload); } else { Logger.log("Approved checkbox: false"); } }}function approve(executionPayload) { const headers = { "Authorization": "Bearer " + ScriptApp.getOAuthToken() }; const params = { "method": 'post', "contentType": 'application/json', "headers": headers, "payload": JSON.stringify(executionPayload) }; const url = "https://workflowexecutions.googleapis.com/v1/projects/" + PROJECT_ID + "/locations/" + REGION + "/workflows/" + WORKFLOW + "/executions"; Logger.log("Workflow execution request to " + url); var response = UrlFetchApp.fetch(url, params); Logger.log(response);}
    5. Replace your-project-id with your Google Cloud project ID.

      You can find your project ID on theWelcomepage of the Google Cloud console.

    6. Click Save save.

  3. Apps Scriptinstallable triggerslet a script project execute a specified function when certain conditions aremet, such as when a spreadsheet is opened or edited. Create a trigger:

    1. Open your Apps Script project.
    2. Click Triggers alarm.
    3. Click Add Trigger.
    4. In the Add Trigger for YOUR_PROJECT_NAME dialog, configure thetrigger:
      1. In the Choose which function to run list, select handleEdit.
      2. In the Choose which deployment should run list, select Head.
      3. In the Select event source list, select From spreadsheet.
      4. In the Select event type list, select On edit.
      5. In the Failure notification settings list, select Notify me daily.
    5. Click Save.
    6. If you receive a prompt to choose a Google Account, select the appropriateaccount, and then click Allow.

      This allows your Apps Script project to see, edit,create, and delete your Sheets spreadsheets; and to connect toan external service.

  4. An Apps Script project manifest fileis a JSON file that specifies basic project information thatApps Script needs to run a script successfully. Note that theApps Script editor hides manifest files by default to protect your Apps Scriptproject settings. Edit the manifest file:

    1. Open your Apps Script project.
    2. Click Project Settings settings.
    3. Select the Show "appsscript.json" manifest file in editor checkbox.
    4. Click Editor code.
    5. The manifest file appears as a project file named appsscript.json. Toedit the file, select it.
    6. The oauthScopes field specifies an array of strings. To set theauthorization scopesyour project uses, add an array with the scopes you want supported. For example:

      { "timeZone": "America/Toronto", "dependencies": { }, "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8", "oauthScopes": [ "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/spreadsheets" ]}

      This sets explicit scopes to:

      • Connect to an external service
      • See, edit, configure, and delete your Google Cloud data and seethe email address for your Google Account
      • See, edit, create, and delete all your Sheets spreadsheets
    7. Click Save save.

Deploy a workflow that creates a VM instance

Deploy a workflow that is triggered when a request to create a VM instance isapproved. The workflow calls theCompute Engine API connectorto create a Compute Engine VM instance based on the specificationscollected through the form.

Console

  1. In the Google Cloud console, go to the Workflowspage:

    Go to Workflows

  2. Click addCreate.

  3. Enter a name for the new workflow: create-vm-from-form.

  4. In the Region list, select us-central1 (Iowa).

  5. For the Service account, select the Compute Engine defaultservice account(PROJECT_NUMBER-compute@developer.gserviceaccount.com).

  6. Click Next.

  7. In the workflow editor, enter the following definition for your workflow:

    main: params: [input] steps: - init: assign: - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")} - zone: ${input.zone} - machineType: ${input.machineType} - diskSize: ${input.diskSize} - imageProject: ${input.imageProject} - imageFamily: ${input.imageFamily} - vmName: ${input.vmName} - email: ${input.email} - createResource: call: googleapis.compute.v1.instances.insert args: project: ${projectId} zone: ${zone} body: name: ${vmName} machineType: ${"projects/" + projectId + "/zones/" + zone + "/machineTypes/" + machineType} disks: - initializeParams: diskSizeGb: ${diskSize} sourceImage: ${"projects/" + imageProject + "/global/images/family/" + imageFamily} type: PERSISTENT boot: true autoDelete: true networkInterfaces: - network: "global/networks/default" result: insertResult - retStep: return: ${insertResult}
  8. Click Deploy.

gcloud

  1. Create a source code file for your workflow:

    touch create-vm-from-form.yaml
  2. In a text editor, copy the following workflow to your source code file:

    main: params: [input] steps: - init: assign: - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")} - zone: ${input.zone} - machineType: ${input.machineType} - diskSize: ${input.diskSize} - imageProject: ${input.imageProject} - imageFamily: ${input.imageFamily} - vmName: ${input.vmName} - email: ${input.email} - createResource: call: googleapis.compute.v1.instances.insert args: project: ${projectId} zone: ${zone} body: name: ${vmName} machineType: ${"projects/" + projectId + "/zones/" + zone + "/machineTypes/" + machineType} disks: - initializeParams: diskSizeGb: ${diskSize} sourceImage: ${"projects/" + imageProject + "/global/images/family/" + imageFamily} type: PERSISTENT boot: true autoDelete: true networkInterfaces: - network: "global/networks/default" result: insertResult - retStep: return: ${insertResult}
  3. Deploy the workflow by entering the following command:

    gcloud workflows deploy create-vm-from-form \ --source=create-vm-from-form.yaml \ --location=us-central1 \ --service-account=PROJECT_NUMBER-compute@developer.gserviceaccount.com

    Replace PROJECT_NUMBER with your Google Cloudproject number. You can retrieve your project number:

    gcloud projects describe PROJECT_ID

Test the end-to-end flow

To confirm that all is working as expected, try running through the entireprocess.

  1. Send your form to yourself and answer the questions appropriately.

    Ensure that the specifications you use to create a VM instance are valid;otherwise, your workflow execution will fail. For more information, seeCompute Engine general-purpose machine family.

  2. To submit your response, click Submit.

  3. Open your form in Forms.

  4. Click Responses.

  5. Click View in Sheets.

    Your linked spreadsheet opens.

  6. In the row for your response, select the Approved? checkbox.

  7. Open your Apps Script project.

  8. Click Executions playlist_play.

    Your trigger should be executed and listed with a status of Completed.

  9. Confirm that the create-vm-from-form workflow completed successfully:

    Console

    1. In the Google Cloud console, go to the Workflowspage.

      Go to Workflows

    2. On the Workflows page, click thecreate-vm-from-form workflow to go to its details page.

    3. On the Workflow details page, to retrieve the details for aparticular execution, click the appropriate execution ID.

      The Execution state should be Succeeded and, in the Inputpane, you should see the VM specifications that you requested.

    gcloud

    Retrieve a list of your workflow's execution attempts:

    gcloud workflows executions list create-vm-from-form

    The result should be similar to the following:

    NAME: projects/918619793306/locations/us-central1/workflows/create-vm-from-form/executions/d8947ecb-9ccb-4ea1-ba10-e5c10414e3beSTATE: SUCCEEDEDSTART_TIME: 2023-01-24T15:07:40.404741791ZEND_TIME: 2023-01-24T15:07:55.649373625Z
  10. Confirm that a new VM was created as expected:

    Console

    In the Google Cloud console, go to the VM instances page.

    Go to VM instances

    Your VM instance should be listed with a status indicating that it isrunning.

    gcloud

    Retrieve an aggregate list of all VMs in all zones for a project:

    gcloud compute instances list

    Your VM instance should be listed with a status indicating that it isrunning.

    For more information about the gcloud compute instances list command,see its reference page.

Clean up

If you created a new project for this tutorial, delete the project.If you used an existing project and wish to keep it without the changes addedin this tutorial, delete resources created for the tutorial.

Delete the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Delete resources created in this tutorial

  1. Delete files in Drive.
  2. Delete a Compute Engine VM instance.
  3. Delete a workflow.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-10 UTC.

Trigger a workflow from Google Sheets  |  Workflows  |  Google Cloud (2024)

FAQs

Trigger a workflow from Google Sheets  |  Workflows  |  Google Cloud? ›

In the Google Cloud console, go to the Service Accounts page. Select a project and then click Create service account. In the Service account name field, enter a name, such as sa-name . Click Create and continue.

How do I automate a workflow in Google Sheets? ›

Creating a Google Sheets Workflow Using Built-In Features
  1. Open the spreadsheet that you want to automate.
  2. Click on the "Tools" menu and select "Macros".
  3. In the "Macros" dialog box, click on the "Create" button.
  4. In the "Create Macro" dialog box, give your macro a name and select the "Create from selection" option.

How do I trigger a cloud function using Cloud Scheduler? ›

You can edit your Cloud Scheduler trigger by modifying the configuration of your Cloud Scheduler job from Cloud Scheduler:
  1. In the Google Cloud console, go to Cloud Scheduler. Go to Cloud Scheduler.
  2. Select the Cloud Scheduler job to edit.
  3. Click Edit.
  4. Modify the Cloud Scheduler job configurations as desired.

How to trigger GCP workflows? ›

Trigger a workflow with events or Pub/Sub messages
  1. Create a trigger using the Google Cloud CLI.
  2. Create a trigger using the console. Before you begin. Configure the trigger.
  3. Create a trigger using Terraform.
  4. What's next.

How do I create a workflow in Google Cloud? ›

In the Google Cloud console, go to the Service Accounts page. Select a project and then click Create service account. In the Service account name field, enter a name, such as sa-name . Click Create and continue.

Does Google have a workflow tool? ›

You can manage workflows from either the Google Cloud console or from the command line using the Google Cloud CLI. Visualization support while editing the Workflows syntax is also available through the Google Cloud console.

Can Google Sheets do automation? ›

You can save time by automating repetitive tasks with macros.

How do I manually trigger cloud function? ›

Test your function with the Google Cloud Console
  1. Go to the Cloud Run functions Overview page.
  2. From the list, click the name of the function that you want to invoke. ...
  3. Click the Testing tab.
  4. In the Configure Triggering Event field, enter any data your function expects as JSON.

How do I deploy a function in Google cloud? ›

Now that you've created your function, you can deploy it in Cloud Shell by following these steps:
  1. Click Cloud Code and then expand the Cloud Functions explorer.
  2. Click a function and then click cloud_upload Deploy function.
  3. In the Quickpick menu, select a Google Cloud project to deploy your function to.

What is cloud trigger? ›

04:21 Cloud Storage triggers enable a function to be called in response to changes in Cloud Storage. 04:27 When you specify a Cloud Storage trigger for a function, you choose an event type and provide a specific Cloud Storage bucket.

How do you trigger a workflow? ›

The following steps occur to trigger a workflow run:
  1. An event occurs on your repository. The event has an associated commit SHA and Git ref.
  2. GitHub searches the . ...
  3. A workflow run is triggered for any workflows that have on: values that match the triggering event.

How do you create a trigger in GCP? ›

Create the trigger
  1. In the Google Cloud console, navigate to Eventarc > Triggers, and then click Create Trigger.
  2. In the Create trigger window, specify the following: Property. ...
  3. Click Create. ...
  4. On the Trigger details page, click the eventarc-event-logger link, and then click the Logs tab.

Can I create a workflow in Google Sheets? ›

Using the tools you already have such as Google Sheets, Google Docs and Gmail, you can create custom workflows that manage your data for you, or use ready-made solutions that are easy to implement for immediate results.

What can I use instead of GCP workflow? ›

Best Paid & Free Alternatives to Google Cloud Workflows
  • Smartsheet.
  • monday.com.
  • Asana.
  • ClickUp.
  • Basecamp.
  • Wrike.
  • ShareFile.
  • Runrun.it.

How do you create a workflow Automation? ›

Steps to Automate Workflows
  1. Step 1: Understand the workflow. ...
  2. Step 2: Draft the workflow. ...
  3. Step 3: Identify opportunities for integration. ...
  4. Step 4: Address the inefficiencies. ...
  5. Step 5: Create the workflow. ...
  6. Step 6: Create the automations. ...
  7. Step 7: Consistently test, monitor, and optimize your workflow. ...
  8. Step 8: Train your team.
Jul 13, 2023

How to use Google Sheets for workflow builder? ›

When you add a Google Sheets step for the first time, you'll need to connect your Google account:
  1. Select the step you'd like to add.
  2. Click Connect.
  3. Select an account, then follow the prompts.
  4. Click Continue.
  5. Return to Workflow Builder to resume editing your step.

Does Google have an Automation tool? ›

Yes! GSuite automation works within a single application or between several programs in the Google Workspace, including: Google Sheets. Google Docs.

Top Articles
Drone Insurance Guide: How to Get Liability & Hull Coverage
Understanding climate bonds
Www.craigslist Virginia
Craigslist Niles Ohio
Lifewitceee
The Potter Enterprise from Coudersport, Pennsylvania
Zitobox 5000 Free Coins 2023
Puretalkusa.com/Amac
Santa Clara Valley Medical Center Medical Records
Our Facility
Used Wood Cook Stoves For Sale Craigslist
Hssn Broadcasts
Cnnfn.com Markets
Telegram Scat
Craigslist Panama City Fl
Q33 Bus Schedule Pdf
Costco Gas Foster City
Shasta County Most Wanted 2022
Carson Municipal Code
Richland Ecampus
Yard Goats Score
Walmart Car Department Phone Number
Https Paperlesspay Talx Com Boydgaming
Shiftselect Carolinas
How to Grow and Care for Four O'Clock Plants
Walgreens On Bingle And Long Point
Dr Seuss Star Bellied Sneetches Pdf
Ordensfrau: Der Tod ist die Geburt in ein Leben bei Gott
Airg Com Chat
Ravens 24X7 Forum
2487872771
What Happened To Father Anthony Mary Ewtn
Wbli Playlist
Ippa 番号
Andhra Jyothi Telugu News Paper
Orion Nebula: Facts about Earth’s nearest stellar nursery
Kerry Cassidy Portal
Gamestop Store Manager Pay
Valls family wants to build a hotel near Versailles Restaurant
Advance Auto.parts Near Me
Mynord
Elven Steel Ore Sun Haven
Catchvideo Chrome Extension
VerTRIO Comfort MHR 1800 - 3 Standen Elektrische Kachel - Hoog Capaciteit Carbon... | bol
Ephesians 4 Niv
Underground Weather Tropical
Theater X Orange Heights Florida
Online TikTok Voice Generator | Accurate & Realistic
Rubmaps H
Costco Tire Promo Code Michelin 2022
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5992

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.