Squirrel learn to code #1: How I create and send personalised PDF from Google Forms for Free


Hello, world!

Recently I've taken a personality assessment and obtained the result in a pdf form. I am wondering if we can create a form and send a personalized result to the given address. I searched the Internet and could not find a site that can do such a thing. And so, being a typical programmer, I write my own code. Read till the end to get the codes!

Thus in today's sharing session, I will share how to create a simple online assessment and immediately send a personalized result to the respondent. Without further ado, these are the steps.

Step 1: Create a form using Google Form
First thing first, let's create a form via Google Form. Here, I created a simple quiz titled "Are you an Introvert?".
Figure 1. Google Form.

Figure 2. Google Spreadsheet.

Step 2: Understanding Responses in Google Spreadsheet



This is the response that I obtained from the Google Form. Before we proceed, I would like to explain briefly the results obtained. In this form, I received the following information:
i. email address
ii. nickname
iii. 5 yes or no questions.

Based on the 5 yes or no questions, I calculate the percentage of being an introvert using the number of 'yes' in the form.

The percentage of being an introvert is used to determine the results that will be sent to the user.

Now we are ready to talk in-depth.

Step 3: Create your program in Google Apps Script Editor

Now, when a user clicked the 'submit' button, we would want to send the result based on the user's responses automatically instead of manually. Thus, in this step, I will show you how.

In your Spreadsheet containing the info from Google Form, go to Tools > Script Editor.
Figure 3. Google Apps Script.



In the script editor, we need first to retrieve the current active spreadsheet. Next, we need to extract the relevant information from each column. We create an iteration to obtain the answers from the question. For each 'yes,' we add to the total score. Then, we calculate the percentage of the total 'yes' response. 
 
For the HTML file design, I use HTML editor. The design is straightforward because this project's main emphasis is on the automation and not the design. I might be covering it in other posts.

When you save the function, you will be prompt to give the script permission to access various features such as sending an email, accessing Google Drive, etc. Just click on Advance and proceed as usual as you're the author of the script.

Step 4: Add trigger effects

As mentioned earlier, I would like to send the result upon form submission immediately. The trick here is whenever a new row is added into the spreadsheet; the code will be executed.

In the Current Project Trigger (click on the icon that looks like a clock. See Figure 3), click on Add Trigger. Add based on the following screenshot  (Figure 4) and hit the 'Save' button. 
Figure 4. Add Trigger.


Now you're all set!

I hope you find this post useful. Do test on your new form and explore beyond this. Enjoy!

And as promised, here is the link for the full code: https://github.com/jiayin88/SquirrelDesign_Codes/blob/main/getPDFResult.gs


Comments

Popular Posts