Skip to content

Instantly share code, notes, and snippets.

View erickoledadevrel's full-sized avatar

Eric Koleda erickoledadevrel

View GitHub Profile
@erickoledadevrel
erickoledadevrel / UnmergedRanges.gs
Last active May 1, 2024 10:08
[Apps Script] Getting the unmerged ranges within a range
/**
* Gets all the unmerged ranges within a range.
* @param {SpreadsheetApp.Range} range The range to evaluate.
* @returns {SpreadsheetApp.Range[]} The unmerged ranges.
*/
function getUnmergedRanges(range) {
if (!range.isPartOfMerge()) {
return [range];
}
var mergedRanges = range.getMergedRanges();
@erickoledadevrel
erickoledadevrel / zendesk.ts
Created March 6, 2024 14:56
Using the password grant to connect to the Zendesk API in a Coda Pack
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
const ClientId = "...";
const ClientSecret = "...";
pack.addNetworkDomain("zendesk.com");
pack.setUserAuthentication({
type: coda.AuthenticationType.Custom,
@erickoledadevrel
erickoledadevrel / moveToCalendar.gs
Last active November 16, 2023 07:02
Moving events from one calendar to another, using Google Apps Script
/**
* Move events with a given title from your primary calendar to another calendar.
* You must enable the Calendar Advanced Service:
* https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services
*/
function moveEvents(eventTitle, fromCalendarName, toCalendarName) {
var fromCalendarId = CalendarApp.getCalendarsByName(fromCalendarName)[0].getId();
var toCalendarId = CalendarApp.getCalendarsByName(toCalendarName)[0].getId();
var now = new Date();
@erickoledadevrel
erickoledadevrel / xmlToJson.js
Created December 1, 2014 14:30
A function to convert an XML string to a JSON object in Apps Script, using logic similar to the sunset method Xml.parse().
/**
* Converts an XML string to a JSON object, using logic similar to the
* sunset method Xml.parse().
* @param {string} xml The XML to parse.
* @returns {Object} The parsed XML.
*/
function xmlToJson(xml) {
var doc = XmlService.parse(xml);
var result = {};
var root = doc.getRootElement();
@erickoledadevrel
erickoledadevrel / pack.ts
Created February 17, 2023 15:33
Pack that authenticates with Supabase
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
// TODO: Set domain and API key.
const ProjectDomain = "<subdomain>.supabase.co";
const ApiKey = <apikey>";
const ProjectUrl = `https://${ProjectDomain}`;
pack.addNetworkDomain(ProjectDomain);
@erickoledadevrel
erickoledadevrel / SendDocument.js
Last active November 30, 2022 12:57
Send a Google Doc in an email using Apps Script
/**
* Sends an email using the contents of a Google Document as the body.
*/
function sendDocument(documentId, recipient, subject) {
var html = convertToHtml(documentId);
html = inlineCss(html);
GmailApp.sendEmail(recipient, subject, null, {
htmlBody: html
});
}
@erickoledadevrel
erickoledadevrel / Code.js
Last active May 9, 2022 09:47
Formatting date/time values using the user's timezone in Apps Script.
/**
* @file A sample showing how to format date/time values in Apps Script so that they appear in the
* user's timezone. View a working version here:
* https://docs.google.com/spreadsheets/d/1VlI8HibL9kh_wlmO0G1ltMGVo6S-urGrDqDbfEp9eeY/edit
*/
/**
* Add menu item after the spreadsheet opens.
*/
function onOpen() {
@erickoledadevrel
erickoledadevrel / FormSubmitFallback.gs
Last active April 9, 2022 18:56
Demonstrate how to create a form submit processing script that can handle missing or duplicate trigger firings.
// Change this values based on your spreadsheet.
var SHEET_NAME = 'Form Responses 1';
var STATUS_COLUMN_NUMBER = 4;
var PROCESSED_STATUS = 'Processed';
var LAST_ROW_KEY = 'lastRow';
var LOCK_TIMEOUT_MS = 60000; // 1 minute
var MAX_RUNTIME_MS = 240000; // 4 minutes
/**
@erickoledadevrel
erickoledadevrel / checkAndHide.gs
Last active April 9, 2022 16:53
Google Apps Script code to hide a row when a checkbox is checked.
/*
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
var CHECKBOX_COLUMN = 'B';
function onEdit() {
var range = SpreadsheetApp.getActiveRange();
if (range.getA1Notation().split(/\d/)[0] == CHECKBOX_COLUMN &&
function onOpen() {
DocumentApp.getUi().createMenu('Demo')
.addItem('Select Spreadsheet', 'selectSpreadsheet')
.addItem('Update Data', 'updateData')
.addToUi();
}
function selectSpreadsheet() {
var result = DocumentApp.getUi().prompt('Enter the ID of the spreadsheet:');
var spreadsheetId = result.getResponseText();