AppsScriptPulse

Allowing access for IMPORTHTML, IMPORTDATA, IMPORTFEED, IMPORTXML, and IMPORTRANGE on behalf of the user in Google Sheets

Image credit: Kanshi Tanaike

In February 2024, Google made a change in Google Sheets to enhance data security. Now, users must provide explicit consent before Sheets can connect to external data sources. This change aims to prevent unintentional data leaks and improve overall data loss prevention within Google Sheets.

Impact on Users:

When manually adding or editing certain IMPORT functions (IMPORTHTML, IMPORTXML, IMPORTFEED, IMPORTDATA) and the IMAGE function in a Google Sheet, a warning banner will appear blocking sending a receiving data until the user gives consent. To enable this functionality, users need to click “Allow access.”

Impact on Developers:

As highlighted in the first source post by Justin Poehnelt, this change caused issues for developers who programmatically create Google Sheets and automate tasks, such as generating PDF documents  as the IMPORT and IMAGE functions were blocked.

Solutions for Developers:

Fortunately, Google introduced an update to the Google Sheets API to address this challenge. Developers can now enable external data access programmatically by setting the importFunctionsExternalUrlAccessAllowed property in the Google Sheet metadata. This allows specific IMPORT and IMAGE functions to work without manual user consent.

For the IMPORTRANGE function, a similar API property is currently unavailable. However, an unofficial workaround exists that involves calling an undocumented endpoint using Google Apps Script as detailed in the second source post by Kanshi Tanaike.

Future Expectations:

As Google continues to prioritize data security, there will likely be further enhancements to data loss prevention controls within Google Workspace. Hopefully, future updates will also include official API controls for IMPORTRANGE and other functions to facilitate legitimate data access for developers while maintaining data security.

Additional Resources:

New Advanced Google Workspace Events service for Google Apps Script


To subscribe to events using Apps Script, you can now use the Advanced Google Workspace Events service.

In the May 02, 2024 Google Apps Script release notes it was announced that a new Advanced Google Workspace Events service is available to let developers use the Google Workspace Events API directly in Google Apps Script. The Google Workspace Events API is a relatively new API, which was released to developer preview in January, 2024. The Google Workspace Events API uses a subscription model to handle resource changes. When you create a subscription, you specify the target resource (such as a Google Chat space or Google Meet meeting space) and the event types that you want to subscribe to. The API then sends notifications to your specified endpoint whenever an event occurs for that resource and event type.

In the case of the new Advanced Google Workspace Events service the linked documentation includes samples for using the new service with Google Chat. It’s worth noting that the Advanced Google Workspace Events service is designed specifically on managing subscriptions to events. While it lets you to control the flow of information and manage event subscriptions in your Apps Script projects, the actual processing and handling of event data occurs separately.

The linked documentation page provides sample code as well as outlines all the prerequisites.

Source: Advanced Google Workspace Events Service

TU5 Special: First Look at Building AppSheet Automations Using the New Google Forms Integration

In this TU Special, we dive into the exciting new features coming to Google AppSheet and take a first look at the new Google Forms integration. For this special our co-host, Martin Hawksey is joined by Steve Franks (Head of Workspace Engineering, CTS Appsbroker). The discussion/demo was originally presented as an internal tech talk conducted at CTS Appsbroker – warning the episode contains some ‘passionate’ language.

Initial key takeaways which we discuss are:

  • Seamless Data Collection: Google Forms now acts as a first-class data source for AppSheet, eliminating the need for workarounds and additional add-ons. Data collected through forms automatically flows into AppSheet, creating a smooth and efficient workflow.
  • External Participation: The integration allows external parties to interact with your apps by simply filling out a Google Form. This opens up new possibilities for data collection and process involvement.
  • Powerful Automations: AppSheet’s automation capabilities can be triggered by form submissions, enabling you to create sophisticated workflows. The example discussed involves sending an email with an embedded AppSheet view upon form completion, allowing for approvals or further actions within the email itself.
  • Simplified Development: The integration makes building apps even easier, especially for those already familiar with Google Forms. The need for complex configurations or AppScripts is minimized, empowering users to focus on the business logic and desired outcomes.
  • Versatility: AppSheet has increased functionality, opening up a wider range of possibilities for app development and automation for Google Workspace customers. It can be used to create full-fledged apps with user interfaces or simply act as a behind-the-scenes automation engine.

Overall, the integration of Google Forms and AppSheet should significantly help empower users to build powerful solutions without coding expertise. Read more about “Build AppSheet automations using Google Forms” on the Google Workspace Updates blog.

Source: TU5 Special: First Look at Building AppSheet Automations Using the New Google Forms Integration

Ever felt like you’re bringing a knife to a gunfight? That’s me coding without `console.table()` in Google Apps Script. Here’s what I did about it.

Here’s the scoop: While tinkering with a project, I needed a way to pinpoint the last row of data in various sheets — essentially to catch any “orphan” values lurking there. Typically, something like console.table() would be the hero of the day, allowing me to effortlessly display data like so:

| Sheet Name | Last Row |
| ---------- | -------- |
| Sheet1     | 513      |
| Sheet2     | 27       |
| Sheet3     | 50       |

But as fate would have it, Google Apps Script doesn’t include a console.table() function, or even a Logger.table()

Source: Ever felt like you’re bringing a knife to a gunfight? That’s me coding without console.table() in Google Apps Script. Here’s what I did about it.

The Ben Collins ‘Google Sheets Tips Weekly Email’ hits issue 300 – Get actionable tips direct to your inbox

Join this community of over 53,600 data analysts and Google Sheets aficionados and get an actionable Google Sheets tip every Monday

With a weekly subscription of over 50K we probably don’t need to flag a ‘Monday morning espresso’ of Google Sheets tips from Ben Collins as you are probably already subscribed. However, given Ben recently published the 300th issue it’s a milestone worth celebrating and a chance to say ‘thank you’ to Ben for this invaluable publication.

As eloquently demonstrated on a recent episode of Totally Unscripted, Ben is the Google Sheets “King of Functions”. Ben’s expertise isn’t limited to solving Google Sheet challenges, he’s also a master at explaining his thinking and helping other people learn. If you haven’t subscribed to Ben’s newsletter follow the source link (it’s free!) and check out Ben’s website for loads of great tips and resources.

Source: The Google Sheets Tips Email – Get actionable tips direct to your inbox

Google Apps Script workflow solution for simplifying date tracking in Google Sheets


Template for a workflow to track tasks that follow steps. It can alert on due and expired steps per each task, while also navigating to alerted cells with a single click. It also demonstrates the use of conditional rules and ARRAYFORMULA.

Sig Mandel has created this clever Google Apps Script solution which might be suitable for anyone struggling to manage tasks and deadlines in Google Sheets. This template lets you easily configure overdue and upcoming deadlines, letting you jump directly to problem areas with a click. It also cleverly uses conditional formatting and ARRAYFORMULA to streamline your task tracking.

You can use the provided Google Sheets template as a starting point and add your workflow steps as columns, input your tasks, and the sheet takes care of the rest. You can also use a number of other features including real-time “toast” messages, a  dynamic installation menu for easy setup, and optimized code for smooth performance.

You can find the template and instructions in the source link or join in the conversation on LinkedIn.

Source: GitHub – zmandel/workflow-apps-script

Google Apps Script: google.script.run vs. doGet/doPost Endpoints

Learn about the different options for making API calls in Google Apps Script web apps: `google.script.run` and GET/POST endpoints (`doGet` and `doPost`). Understand their strengths and weaknesses to choose the best approach for your project.

Google Apps Script web apps are a popular way to publish user interfaces for automation processes. I’d never really considered the decision between google.script.run and GET/POST endpoints (doGet and doPost) when making server side calls, but as outlined in this post from Justin Poehnelt there are scenarios where both of these approaches might be most appropriate. Justin also provides some useful code snippets to help you get started with both methods. Follow the source link to read more…

Source: Google Apps Script: google.script.run vs. doGet/doPost Endpoints | Justin Poehnelt

Avoiding Google Apps Script onFormSubmit simultaneous executions when unlinking/linking Google Sheet responses

Caution when using onFormSubmit triggers to avoid mass simultaneous executions when un/linking a Response Sheet.

The following post is a caution around onFormSubmit triggers after I recently discovered a way that somebody had inadvertently managed to execute my code simultaneously over 253 times. Now unless a Google Form is submitted by 253 individuals all at the same time … then this is baffling.

When should an onFormSubmit trigger run?
At the point when a Google Form has been completed and the ‘Submit’ button pressed.

How else can the trigger be activated?
Well … it turns out when you unlink and then link back a Google Response Sheet containing the onFormSubmit trigger, it will activate it for every single Form response collected up to that point in time …

Source: The Gift of Script: onFormSubmit Trigger simultaneous executions

Answer questions based on Google Chat conversations with a Gemini API powered Chat app

This tutorial shows how to make a Google Chat app that answers questions based on conversations in Chat spaces with generative AI powered by Vertex AI with Gemini. The Chat app uses the Google Workspace Events API plus Pub/Sub to recognize and answer questions posted in Chat spaces in real time, even when it isn’t mentioned.

Here is another great tutorial from the Google Chat DevRel team, this time showcasing how the Google Workspace Events API and some new Google Chat UI elements can be used to turn a Chat space into a Gemini Pro powered knowledge base.

The sample solution will let you consume your Chat space message history into a Firestore database. The Chat app is an intelligent agent that can then monitor for new questions and make suggestions using Gemini to generate content based on the previous messages.

There is quite a bit of setup required as part of this tutorial, but it provides a solid foundation for quickly scaling this to your needs.  A demonstration and explanation of the sample app was given as part of the Google Chat apps and APIs: Build connected workflows for the hybrid workplace session at Google Cloud Next and a recording might be available soon!

Source: Answer questions based on Chat conversations with a Gemini AI Chat app  |  Google Chat  |  Google for Developers

How to access secrets from Google Secret Manager using Google Apps Script

This detailed guide explains how you access your passwords, API keys and other sensitive data stored in the Google Secret Manager with Google Apps Script.

API keys and other credentials are your digital passports to access valuable data and services from various online platforms. When you’re developing Google Apps Script projects that connect to using keys, it’s of paramount importance to handle these keys with care and prevent them from falling into the wrong hands. Mishandled API keys can lead to unauthorized access, data breaches, and potentially even financial consequences.

One way to store API keys in Google Apps Script is the built-in Properties Service. This service offers a mechanism to store key-value pairs attached to your Apps Script project. While the Properties Service offers a convenient way to store sensitive data, it comes with limitations:

  • Not True Encryption: The Properties Service stores data in a readable format. Anyone with sufficient access to your Apps Script project might be able to view the API keys.
  • Limited Access Control: It’s challenging to implement fine-grained access restrictions over who can see the stored keys within the Properties Service.

For a more secure and scalable approach you might consider using Google Cloud’s Secret Manager. As described by Amit Agarwal in this source post:

Google Secret Manager is a cloud service where you can store sensitive data such as passwords, database credentials, encryption keys or any other confidential information that you don’t want to hardcode in your application’s source code. You can also set up an expiration time for the secret and the Google Secret Manager will automatically delete the secret after the specified time.

You can read more about using the Google Cloud Secret Manager in Amit post, which also includes the setup and Apps Script code snippets to make it work. For some general best practices on key management, Google provide this support article.

Source: How to Access Secrets from Google Secret Manager using Apps Script – Digital Inspiration