Is it possible to send a google form with a trigger from a spreadsheet value? if so where would I go for help?
I Have created a google form that can be viewed here http://www.leadersoftomorrowisn.org/Become_a_Member.html
I want to be able to take the responses from question 5 "What Are You interested in?" and use them to send out specific google forms.
Is it possible to send a google form with a trigger from a spreadsheet value? if so where would I go for help with that?
Best,
Maxwell
Let's assume that your Become a Member form has a spreadsheet that receives responses, and that you will create a script with a Form Response trigger that will review the responses as they come. We'll call that trigger onFormSubmit()
. You have the option to create this trigger function contained within a Form Script, or within a Spreadsheet Script - either of those containers can receive the form responses. This choice will dictate which Event will be received by onFormSubmit()
- see Understanding Events for details.
You will create (or already have) a set of additional Google Forms for the range of interests. Each of these forms has a unique id, and that's what you will use to obtain a URL for the form that you will send to respondents. See Class FormApp for API details. For each of your interest forms, you will need to embed the unique id into the script - that id appears in the URL while you're in the Form Editor, or on the Live Form.
In onFormSubmit
, you can use the Form Submission Event to read a copy of the current response. Your question 5 is a checkBox
question, so all checked answers will be delivered in a comma-delimited string. (Be careful not to have commas in your questions!) In the example below, we're split
ting the response to question 5 to get an array of interests, and then sending email links to additional surveys based on those. It's quite crude, and very tightly coupled with your form, but it should do the trick.
function onFormSubmit(event) {
// Get the responses into convenient variables.
var firstName = event.values[1]; // Question 1
var lastName = event.values[2]; // Question 2
var email = event.values[3]; // Question 3
var allInterests = event.values[5] // Question 5, a comma-separated list,
.split(','); // which we turn into an array
// Loop over all expressed interests, sending surveys
for (var interest in allInterests) {
sendInterestSurvey( firstName, lastName, email, allInterests[interest] );
}
}
/**
* Determine the id for a form that matches the given survey (interest),
* and send an email to the respondent.
*/
function sendInterestSurvey( firstName, lastName, email, survey ) {
var surveyFormId = null; // Will fill with appropriate survey ID
// Set serveyFormId according to current value of 'survey'.
switch (survey) {
case "Becoming an LOT Member of the USD Chapter":
surveyFormId = '1234567890abcdefghijklmnopqrstuvwxyz'; // Replace with real form ID
break;
case "Presenting a business idea at one of USD's Business Opportunity Meetings (Spring 2014)":
surveyFormId = '1234567890abcdefghijklmnopqrstuvwxyz'; // Replace with real form ID
break;
// and so on...
default:
// Error handling, or for "other"
break;
}
// Send an email for any interest with a survey form
if (surveyFormId != null) {
var existingForm = FormApp.openById(surveyFormId);
var surveyURL = existingForm.getPublishedUrl();
var surveyTitle = existingForm.getTitle();
// Build Email Body
var body = 'Dear '+firstName+' '+lastName+',<br><br>'; // Dear John Doe,
body += 'Thanks for completing our Member Contact Information.<br><br>';
body += 'You expressed an interest in: ' + survey;
body += ', and we would like to get more details about your interest.<br><br>';
body += 'Please follow <a href="' +surveyURL+ '">this link</a> to complete the survey.<br><br>';
body += 'Thank you!';
MailApp.sendEmail({
to: email,
subject: surveyTitle,
htmlBody: body
});
}
}
You could take this further, for instance you could generate a URL for a pre-filled version of the additional surveys, with the respondent's name already filled in.