-
-
Save DerekCaelin/fb13d85e4bcd503217cc5793c27dfc08 to your computer and use it in GitHub Desktop.
/* | |
If you want entries on a Google form to auto-create a Trello card, | |
you can follow the steps below. | |
There are two ways to connect a Google form to a Trello board. One of them | |
involves using the Trello API. This version instead works by sending an email to a | |
Trello board's private email address and then it creates cards based off the content | |
of the email. | |
Trello will make a card with a title that matches the "subject" line of the | |
email. The description will match the message within the email. | |
1. Create a Google form with a number of questions. | |
2. In the settings of the Google form, select "< > Script Editor" | |
3. Replace the pre-existing text with the text from this form. | |
4. Adapt the code: | |
- Replace the email adress that the script will send to with the email address you find on the Trello board. (Menu > More > Email-to-Board Settings) | |
- Change the content of the email message. | |
5. On the code page, go to Resources > Edit > All Your Triggers. Add a new trigger that runs onFormSubmit. (This will run the "onFormSubmit" function in your code when someone clicks "Submit" on the Google Form. | |
6. When prompted, provide necessary permissions for your google script to send emails on your behalf, etc. | |
*/ | |
//Form Variables | |
var form; //this is your Google form | |
var responses; //is a collection of all the responses that are provided by the goolge form | |
//Google Form responses | |
//these are the individual responses that come with your form. Change the number of your what. | |
var entry1; | |
var entry2; | |
var entry3; | |
//email content | |
var trelloEmail = "[email protected]"; //This is the email address of your trello board. | |
var trelloTitle; //This is the Subject Line of the email your script will send. | |
var trelloDescription; //This is the Body of the email your script will send. | |
function onFormSubmit(e) { | |
form = FormApp.getActiveForm(); | |
responses = e.response.getItemResponses(); | |
//assign variables | |
AssignVariables (); | |
//build email | |
BuildEmail(); | |
//send email | |
SendEmail(); | |
} | |
//Get the value of variables from the form | |
function AssignVariables(form){ | |
entry1 = responses[0].getResponse(); | |
entry2 = responses[1].getResponse(); | |
entry3 = responses[2].getResponse(); | |
} | |
function BuildEmail(){ | |
trelloTitle = 'Google Form Entry'; | |
trelloDescription = 'Values from your Google form include: ' + '\n' + entry1 + ', ' + entry2 + ', ' + entry3 + '.'; | |
} | |
function SendEmail(){ | |
MailApp.sendEmail(trelloEmail, title, message); | |
} |
Hey. How do I change the list the card goes in?
Also how do I add a label?
Labeling
In the subject, add #labelname, #labelcolor, or #labelnumber. If your label consists of two or more words, in the subject line either join the words or use underscores between the words. For example, if your label is named "To Do" in the subject line of your email either enter #ToDo or #To_Do for the label to render properly on your card. If you have multiple labels in a board with the same color or the same name, emailing a board with #color or #name will only add the first label with that color or name to the card.
Lists
I don't believe you can set the card to go to different lists via email. If you find a way, please let me know.
Thank you.
Wait so at the minute, will it just go to a random list?
No, check the documentation I shared. When you set up the option to create cards by email, you select a destination list in the Trello GUI.
Oh okay. Thanks again!
I kept getting a failure message of TypeError: Cannot read property 'getResponse' of undefined
. After debugging, the fix seems to be starting the value extraction from the responses
array at 0: entry1 = responses[0].getResponse();
Thanks for sharing this script, it's saved me a lot of time and money setting up a paid integration service.
Thanks for sharing! I've updated the gist.
Hi there (code noobie here)
I am getting the following error : TypeError: Cannot read property 'response' of undefinedonFormSubmit @ Code.gs:18
Can you maybe please advice?
How can I get the form submitted time in Trello card ?
Unless I am misunderstanding this code, there's a mistake in the SendEmail function. The function sends an email using the email address provided in the code, but the variables "title" and "message" are not defined variables for the function call. Should it instead have trelloTitle and trelloDescription in place of those two variables?
It looks like there's a similar error in the AssignVariables function and its use. The function requests the variable "form", but in the function call, no value is given. In the execution of the function, it instead uses only the responses variable and doesn't require the input variable. This also means that fetching the form variable is unnecessary.
When a form is submitted, its information passes into 'e'. You pull information from e into "responses" (ln 41) and then break responses down into independent variables on 54.