Skip to content

Instantly share code, notes, and snippets.

@BFinc
BFinc / Google Apps Script Survey Workflow.md
Created September 13, 2017 23:05 — forked from mogsdad/Google Apps Script Survey Workflow.md
Google Apps Script workflow for an email survey. Written in response to StackOverflow question 18668828. http://stackoverflow.com/a/18669532/1677912

Google Apps Script Survey Workflow

The components involved in this workflow are:

  • A script to generate and send an email with an HTML form.
  • An html template for that email, which allows us to customize the email for each recipient.
  • A doPost() function to handle responses. The script must be [deployed as a Web App][1].
  • A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)

Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:

@BFinc
BFinc / SimpleSalesforceConnection.js
Created December 7, 2017 23:55 — forked from stomita/SimpleSalesforceConnection.js
A Google Apps Script, which simply connects and fetches data from Salesforce RESTful API with OAuth authentication.
/**
* Connect and fetch Salesforce data via OAuth
*/
function queryDataFromSalesforce() {
// Read OAuth consumer key / secret of this client app from script properties,
// which can be issued from Salesforce's remote access setting in advance.
var sfConsumerKey = ScriptProperties.getProperty("sfConsumerKey");
var sfConsumerSecret = ScriptProperties.getProperty("sfConsumerSecret");
if (!sfConsumerKey || !sfConsumerSecret) {
Browser.msgBox("Register Salesforce OAuth Consumer Key and Secret in Script Properties");
var AUTHORIZATION_URL = "https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}&state={state}";
var ACCESS_TOKEN_URL = "https://login.salesforce.com/services/oauth2/token";
var CLIENT_ID = "input your client_id";
var CLIENT_SECRET = "input your client_secret";
var REDIRECT_URI = "https://script.google.com/macros/s/********************/usercallback";
/**
* メニューの設定
*/
function onOpen() {
@BFinc
BFinc / cbl.js
Created January 24, 2018 20:07 — forked from patt0/cbl.js
ContinuousBatchLibrary is a Google Apps Script library that manages large batches and works around the 5 minute limitation of GAS execution. It does this by setting time based triggers in the future as well as memorising the last processed key in the batch in order to restart from the correct position. At the end of the batch a cleanup function …
/**
* --- Continous Execution Library ---
*
* Copyright (c) 2013 Patrick Martinent
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@BFinc
BFinc / README.md
Created March 22, 2018 23:48 — forked from chrislkeller/README.md
SpreadSheet To Fusion Tables

Script to sync a Google SpreadSheet to a Fusion Table

Save for a few legacy projects that still use Fusion Tables I don't actively use this script anymore. This update hopefully solves the OAuth issue that cropped up once Google depcricated the Client Login method used by the prior version.

As always, your mileage may vary, and I welcome someone -- Google or otherwise -- to offer a long-term maintained solution.

The following is largely cribbed from a Google example here. I try to explain some of the API settings that must be enabled in the Developer's Console and elsewhere

Create your spr

@BFinc
BFinc / httpGetTemplate.gs
Created March 23, 2018 17:47 — forked from mogsdad/httpGetTemplate.gs
Google Apps Script template functions for external host communication with UrlFetchApp. See https://mogsdad.wordpress.com.
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* httpGetTemplate.gs
*
* A pair of template functions for external host communication with
* UrlFetchApp, including parameter encoding and error handling.
*
* From: gist.github.com/mogsdad/a76c32231a2b91ff8b59
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@BFinc
BFinc / xmlToJson.js
Created March 27, 2018 18:04 — forked from erickoledadevrel/xmlToJson.js
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();
@BFinc
BFinc / Apps Script pdfToText utility.md
Created May 30, 2018 17:34 — forked from mogsdad/Apps Script pdfToText utility.md
For http://stackoverflow.com/questions/26613809, a question about getting pdf attachments in gmail as text. I got a little carried away - this does much more than asked.

Google Apps Script pdfToText Utility#

This is a helper function that will convert a given PDF file blob into text, as well as offering options to save the original PDF, intermediate Google Doc, and/or final plain text files. Additionally, the language used for Optical Character Recognition (OCR) may be specified, defaulting to 'en' (English).

Note: Updated 12 May 2015 due to deprecation of DocsList. Thanks to Bruce McPherson for the getDriveFolderFromPath() utility.

    // Start with a Blob object
    var blob = gmailAttchment.getAs(MimeType.PDF);
    
@BFinc
BFinc / gist:4ee34e58f6a02a638ddc1f5fc8f55402
Created June 16, 2018 15:42 — forked from mhawksey/gist:1442370
Google Apps Script to read JSON and write to sheet
function getJSON(aUrl,sheetname) {
//var sheetname = "test";
//var aUrl = "http://pipes.yahoo.com/pipes/pipe.run?_id=286bbb1d8d30f65b54173b3b752fa4d9&_render=json";
var response = UrlFetchApp.fetch(aUrl); // get feed
var dataAll = JSON.parse(response.getContentText()); //
var data = dataAll.value.items;
for (i in data){
data[i].pubDate = new Date(data[i].pubDate);
data[i].start = data[i].pubDate;
}
@BFinc
BFinc / jsonstream.js
Created June 24, 2018 14:57 — forked from watson/jsonstream.js
Example of using the JSONStream module
var request = require('request')
var JSONStream = require('JSONStream')
var opts = {
url: 'https://api.github.com/users/watson/repos',
headers: {'User-Agent': 'request'}
}
request(opts)
.pipe(JSONStream.parse('*'))