Call Apps Script from an automation

Call Apps Script from an automation as described in the following sections:

Overview

Apps Script is a cloud-based JavaScript platform that lets you integrate with and automate tasks across Google products. With Apps Script, you write code in modern JavaScript and have access to built-in libraries for Google Workspace applications.

You can use custom logic from within your AppSheet app by calling Apps Script from an AppSheet automation bot.

Examples of custom logic that you can implement include:

  • Create a calendar appointment when a button is clicked
  • Add a slide to a presentation when a new row is added
  • Save photos to Drive and share with specific individuals when uploaded using a form
  • Create an audit log by generating a Google Docs file with data from a table
  • Call an external service for machine learning prediction using data from a newly added row and write back model prediction

New to Apps Script? See Google Apps Script overview.
New to AppSheet Automation? See AppSheet Automation: The Essentials.

Get started calling Apps Script from an automation

Get started calling Apps Script from an automation.

Create an Apps Script project

First, you must create an Apps Script project for your script files and related resources. An Apps Script project includes:

  • One or more script files (.gs) to define your custom integrations
  • Optionally, HTML files, that might include JavaScript and CSS, to create custom templates and layouts

Create an Apps Script

To create an Apps Script project:

  1. From the Apps Script home page you can:

    • Create a new Apps Script project, as described in Create and delete projects.

    • Copy an existing Apps Script project:

      1. Open the Apps Script project editor.

      2. Click Overview in the left sidebar and click Make a copy (copy icon) in the right side of the page.

  2. Add one or more scripts to the project or modify the existing scripts. For examples, see Use the AppSheet Apps Script Examples project.

Add and configure the "Call a script" task in a bot

Add and configure the Call a script task in a bot by performing the following steps.

For more information about adding and configuring tasks in an automation bot, see Tasks: The Essentials.

  1. Add the Call a script task to an automation bot in one of the following ways:

    • Choose from the list of suggestions. AppSheet Automation is an intent-aware platform. The platform understands user intent and recommends configuration options that align with what you are trying to achieve. For example, selecting the following bot suggestion would configure a basic Send an email task for you:

      When a new NationalParks record is created, send an email

    • Reuse an existing task. When creating a custom step in a process, click Run a task and select an existing task from the list.

    • Create a custom task.

      • When creating a custom step in a process, click Run a task, then select Create new task in the Task to run list to create a reusable task and include it in the existing process (as shown below).

      • Select Automation > Tasks and click + New Task to create a reusable task that can be used in any bot process. See About task reusability.

        Add a Call a script task to an automation bot

  2. Configure the Call a script task by using the settings described in Configure the "Call a script" task (below). For example:

    Configure the Call a script task

  3. Click Authorize to authorize the Apps Script project to run.
    Note: You'll need to authorize the first time you access the project and anytime authentication scopes are added. As indicated, the script will always run as the app owner regardless of the account used to authorize the project.

  4. Select the Apps Script function that you want to call in the Function Name drop-down.
    The list is populated using the functions defined by the Apps Script project selected in the previous step. After you select the function, the list of associated arguments is displayed. For example:

    Select Apps Script function and define the arguments using expressions

  5. Enter an expression that defines each argument that will be passed to the function in the Function Arguments field.

  6. Optionally, enable the Return Value option to use the return value from the Apps Script function. See Use return values from Apps Script tasks for more information.

  7. When you are done, save the task by selecting one of the following:

    • Save - Save the app
    • Save & verify data - Save the app and verify the data defined.

Configure the "Call a script" task

Configure the Call a script task by using the settings in the following table.

Setting

Description

Linking

Enable or disable reuse of this component by expanding the Linking panel and toggling the Linking setting. See Reuse automation components.

Expand the Linking panel and toggle the Linking setting to enable or disable component reuse

Task name

Name of the task that appears in the automation process flow. It must be unique within your app.

Table name

Table referenced by the task. Select an existing table in the list. Click View definition to view the structure of the selected table.

See Tables: The Essentials for more information about adding tables.

Apps Script Project

Apps Script project that contains the function you want to call. To populate the field:

  1. Click Browse (File icon).
  2. Click Files on Google Drive.
  3. Navigate to the Apps Script project in your Drive. See Create an Apps Script project.
  4. Click Select.

Click Open Project to open the project, if desired.

Share an Apps Script project

Share your Apps Script project by sharing it directly or using a shared drive. For details, see Collaborating with other developers.

Manage Apps Script projects in your AppSheet account

The following sections describe how to manage Apps Script projects in your AppSheet account:

View Apps Script projects in your AppSheet account

To view Apps Script projects in your AppSheet account:

  1. Sign in to AppSheet.
  2. Go to the My account page.
  3. Select Integrations > Apps Scripts.

The Apps Script projects are displayed, as follows:

View Apps Script projects in your account on the Integrations > Apps Script pane

Add an Apps Script project to your AppSheet account

When you add and configure a Call a script task, the Apps Script project is added to your account automatically.

Remove an Apps Script project from your AppSheet account

Remove access to an Apps Script project from your AppSheet user or team account so that it is no longer available for use by other apps.

Note: Before removing an Apps Script project from your AppSheet account, you should delete all references to the Apps Script project in your apps to avoid errors. If you removed a project from the My Account page, and want to add the project back to your account, select the script again from within the “Call a script” flow.

To remove an App Script to your user or team account:

  1. Sign in to AppSheet.
  2. Go to the My account page.
  3. Select Integrations > Apps Scripts.
  4. Click Delete (Trash icon) to delete access to a particular script.

Quotas and limitations

  • Apps Script executions are subject to standard Google Workspace quotas and limitations as stated in Quotas for Google Services.
  • Apps Script tasks will be available for users in the AppSheet Core plan and above. See AppSheet pricing plans.
Was this helpful?
How can we improve it?
Search
Clear search
Close search
Google apps
Main menu
Search Help Center
false
false