Skip to content

Instantly share code, notes, and snippets.

@jezhou
Created September 26, 2015 09:46
Show Gist options
  • Save jezhou/ac34cef8ce02aa051cfd to your computer and use it in GitHub Desktop.
Save jezhou/ac34cef8ce02aa051cfd to your computer and use it in GitHub Desktop.
Create Trello Card from Google Forms using Google Apps Script
// Fire off this function in the script editor to enable.
function init() {
var triggers = ScriptApp.getProjectTriggers();
var form = FormApp.getActiveForm();
// Delete all triggers before making a brand new one.
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
// Set up a new trigger
ScriptApp.newTrigger('submitToTrello')
.forForm(form)
.onFormSubmit()
.create();
Logger.log('Successful creation of new submitToTrello trigger.');
}
function submitToTrello(e) {
var form = FormApp.getActiveForm();
var latestItemResponses = form.getResponses().pop().getItemResponses();
if (MailApp.getRemainingDailyQuota() > 0) {
// Trello email address goes here
var email = "TRELLO BOARD EMAIL";
// Subject line will be the title of the event on Trello card
var subject = latestItemResponses[3].getResponse();
// Intial empty body
var body = "";
// Loop through recent responses and format them into string
latestItemResponses.forEach(function (value, index, array) {
var formatted = Utilities.formatString("**%s**\n %s\n\n", value.getItem().getTitle(), value.getResponse());
body = body.concat(formatted);
});
MailApp.sendEmail(email, subject, body);
}
}
@jezhou
Copy link
Author

jezhou commented Sep 26, 2015

This takes advantage of the fact you can send email data to your Trello Board and have it make a card.

NOTE: This only works for bounded google forms and can be a bit slow to send. It might be better to use the Trello API as a long term solution.

@blairbo
Copy link

blairbo commented Mar 18, 2018

Hello! Thanks for this script.

I get this error (from Execution Transcript):
[18-03-17 20:03:51:412 EDT] FormApp.getActiveForm() [0.202 seconds]
[18-03-17 20:03:51:574 EDT] Starting execution
[18-03-17 20:03:51:786 EDT] FormApp.getActiveForm() [0.205 seconds]
[18-03-17 20:03:51:909 EDT] Form.getResponses() [0.122 seconds]
[18-03-17 20:03:51:911 EDT] FormResponse.getItemResponses() [0.001 seconds]
[18-03-17 20:03:52:440 EDT] MailApp.getRemainingDailyQuota() [0.527 seconds]
[18-03-17 20:03:52:444 EDT] Execution failed: TypeError: Cannot call method "getResponse" of undefined. (line 33, file "Code") [0.861 seconds total runtime]

Any idea where i'm going wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment