Conduct app monitoring, data backup, and data analysis for your MongoDB … This article shares a simple way to achieve this using Google Sheets and Apps Script. In this article, you will learn how to:
Populate MongoDB data in Google Sheets for analysis
Receive daily reports of your app’s growth metrics via email
Often the hardest part of interacting with other services using Google Apps Script is working out the payload you need to send with UrlFetchApp. Despite having almost 1,000 posts in AppScriptPulse, this is the first post featuring MongoDB. The source post has all the code and setup instructions to start collecting MongoDB data into Google Sheets as well as sending a daily email report of selected metrics.
The first step in conducting research involves acquiring an appropriate dataset. .. Apps Script is a scripting platform developed by Google, that provides a user-friendly interface that enables easy automation and interaction with various Google services, including YouTube’s API.
For many years I was custodian of TAGS, a Google Sheets solution to archive Twitter searches. This came to an abrupt end when Twitter put a hefty paywall on API access. I’m sure there were ‘bad actors’ using TAGS, but I was also aware there were a number of academics and students using this solution to help make the world a little better. As noted in this source post “Dataset plays a crucial role in ensuring the accuracy and dependability of the results we obtain”.
For social scientists looking for new datasets this post from Randie Pathirage highlights how you can use Google Apps Script to get comments on YouTube videos using the YouTube Data API.
Automatically create PDFs with information from sheets in a Google Sheets spreadsheet. Once the PDFs are generated, you can email them out directly from Sheets. This solution focuses on creating custom invoices, but you can update the template and script to fit your needs.
Today as part of a customer Google Apps Script introduction workshop, we covered a basic invoice / PDF example. By coincidence this month’s Google Workspace Developers Newsletter highlighted a solution spotlight from the Apps Script samples catalogue which does something very similar.
A trick I learned today from our Lead Workspace Trainer, Tim McLardy, was rather than using UrlFetchApp to get a PDF version of the Google Sheet with the export/?format=pdf url, is instead getting the Google Sheet as a blob and creating a pdf with DriveApp.createFile(). As this technique will generate a PDF with pages with all your Sheet tabs the trick is to selectively hide all but the tabs you want in your PDF. In the case of the example linked as the source post you can rewrite the createPDF() function as:
/**
* Creates a PDF for the customer given sheet.
* @param {string} ssId - Id of the Google Spreadsheet
* @param {object} sheet - Sheet to be converted as PDF
* @param {string} pdfName - File name of the PDF being created
* @return {file object} PDF file as a blob
*/
function createPDF(ssId, sheet, pdfName) {
// Based on https://webapps.stackexchange.com/q/162155/30021
const ss = sheet.getParent();
const sheets = ss.getSheets();
// Hides all sheets that are not the main one
sheets.forEach(s => {
if (s.getSheetName() !== INVOICE_TEMPLATE_SHEET_NAME) {
s.hideSheet()
}
});
// make a pdf of the sheet
const folder = getFolderByName_(OUTPUT_FOLDER_NAME);
const pdfFile = folder.createFile(ss.getBlob()).setName(pdfName);
// show all the sheets
sheets.forEach(s => s.showSheet())
return pdfFile;
}
A useful library to create prettified HTML, XML GraphML and other markups directly from Apps Script or JavaScript.
A long, long, long time ago Apps Script had a Xml class which was deprecated in favour of the current XML Service. One of the nice features of the old Xml class was the Xml.parseJS() method, which “given a JavaScript array … returns an XmlDocument representation”.
The current XML Service doesn’t have a JavaScript to XML parser, but Bruce Mcpherson has recently shared a library that can be used to easily convert JSON objects into XML and it’s many recognised formats like HTML. Bruce’s post shows how to can create various HTML page elements including head sections and tables. It’s also worth checking out Bruce’s other post on “Create GraphML markups from Apps Script” which is included in the source link.
Learn how to use the Udemy API with Google Apps Script to find free programming courses on Udemy on any topic.
A double win in this post from Amit Agarwal. Not only can you get a list of free programming courses currently running on Udemy, but Amit includes the code snippet used to get/add these to a Google Sheet. This might be useful if you are working with other APIs and are looking for a code snippet to help format the data in a Google Sheets friendly format.
We recently launched the Google Workspace APIs Explorer, a new tool to help streamline developing on the Google Workspace Platform. What is this handy tool and how can you start using it?
The Google Workspace APIs Explorer is a tool that allows you to explore and test Google Workspace APIs without having to write any code. It’s a great way to get familiar with the capabilities of the many Google Workspace APIs.
The Google Apps Script editor bakes in some nice features including inline documentation to help when you are coding your script project (and if you don’t already know, next time you are in the online script editor press ctrl + space :). To help with discovery Google have recently published the Google Workspace APIs Explorer website, which lets you see and test a range of Google APIs. For Google Apps Script developers this site is a great way to help you understand how you can use the Advanced Services (my tip for Workspace admins is to check out the Directory and Report API which as part of the Admin SDK API Advanced Service).
Sending out emails as a part of a Google Workspace automated workflow is a very common task. In Google Apps Script we can send emails to users using the MailApp.sendEmail(), the GmailApp.sendEmail() method or even as a JSON payload with the Gmail Advanced API service.
While one might expect that the sender’s signature block would also be transmitted with the automated email, we find that this is not in fact the case.
Scott Donald highlights some of the pitfalls of trying to access the Gmail signatures using Google Apps Script. Fortunately Scott also shares a workaround for using a Gmail draft to store a number of signatures/snippets. This is all wrapped in a handy getSignatureBlock() function, created and shared by Scott to get either the user’s primary signature block or one stored in a draft.
Highlight Duplicate Rows in spreadsheets efficiently and accurately with Google Apps Script for coders and non-coders.
Some nice techniques in this post which shows you how you can highlight duplicate rows in a Google Sheet using Google Apps Script. If you need to modify there is a isDuplicateRow() which could be modified to suit your needs. Another nice solution in this example is the inclusion of function to getRandomUniqueColor(), which returns a random hex colour.
Have you ever wished for a personal assistant who could give you a quick summary of your day’s events while you’re busy getting ready in the morning? I worked on a Google Apps Script that does just that! By collecting events from in Google Calendar, generating a summary using ChatGPT, and creating a voice file with Google Text to Speech, the script will send a daily summary straight to their Google Chat Spaces.
Not surprising given the current interest in generative AI to see more examples emerging from the Google Workspace developer community. This latest example comes from Stéphane Giron who shares how he is able to recreate some Google Assistant functionality with Google Apps Script and calls to the ChatGPT and Google Cloud Text to Speech services. All the main code snippets from this project are available in the source post link.
If you are playing around with Sheet colors with Apps Script, you sometimes find yourself with font colors that don’t go well with the background colors you’ve chosen. However, we can use Yiq values to decide whether the luminance of the background color would be best with a light or a dark foreground font color. Here’s a small Apps Script library to figure it out for you.
Nice little helper library from Bruce Mcpherson if you’ve like to automatically apply contrasting colours to Google Sheets ranges. The source post from Bruce provides the background to the YIQ colour system as well as how to use the library. Follow the source link for more details.