Skip to main content

How to customize email content based on logical blocks for Google form to Email Notification

Introduction

This feature allows you to customize the content of emails sent from Google Forms notifications using logical blocks. You can define conditions that will determine which parts of the email content are included in the final email sent to recipients.

note

This feature works only inside HTML Editor.When you create a processor you have to select HTML Editor to Customize the Email body.

Structure of codeblocks

The code used to customize email content is structured using code blocks with the following format:

{%codeblock%}
{%condition%}
<!--This is where you will write the JavaScript code that defines the condition for including the content-->
{%endcondition%}
{%result%}
<!--This is where you will write the HTML content that you want to include in the email.This can be formatted using HTML-->
{%endresult%}
{%codeblock%}

Meaning of each section of code blocks

  • {%codeblock%}: This marks the beginning of a code block.
  • {%condition%}: This section defines the condition that will be evaluated to determine whether to include the following content in the email.
  • {%endcondition%}: This marks the end of the condition section.
  • {%result%}: This section contains the content that will be included in the email if the condition evaluates to true.
  • {%endresult%}: This marks the end of the result section.
  • {%endcodeblock%}: This marks the end of the code block.

Sample code blocks

Here is a sample code block that checks if the answer to the question "Age" is greater than 18 and includes a specific message in the email if the condition is true:

{%codeblock%}
{%condition%}
{{Age}} > 18
{%endcondition%}
{%result%}
<p><i><b>Age is greater than 18 so you are seeing this result.</b></i></p>
{%endresult%}
{%endcodeblock%}

Here is a sample code block that checks if the answer to the question "Name" has a lnegth greater than 5 and includes a specific message in the email if the condition is true:

{%codeblock%}
{%condition%}
var x = '{{Name}}';
if(x.length> 5) return true ;
else return false;
{%endcondition%}
{%result%}
<p><i><b>Name length is greater than 5 </b></i></p>
{%endresult%}
{%endcodeblock%}

Here is a sample code block that read a check box Question "CB Answer" It reads the answers in a string and evaluates the answers.If the answers are CB1 and CB3 it evaluates to true

{%codeblock%} 
{%condition%}
var x = '{{CB Answer}}'; let cbAnswerArray =x.split(','); if(cbAnswerArray.at(0) == 'CB1' && cbAnswerArray.at(1) == 'CB3' ) return true ;else return false;
{%endcondition%}
{%result%}
<p><i><b>two check boxes with answers CB1 and CB3 are present</b></i></p>
{%endresult%}
{%endcodeblock%}

Things to Note about condition block

  • Condition block must evaluate to a boolean value .
  • You can use single line statement like {{Age}} > 18 and it will be true if Age is greater than 18.
  • In multi line code you must return a boolean value.
  • You can write javascript syntax.
  • We impose certain restrictions on what functions can be used which is mentioned below.
  • Only if/else and for loops are supported.

Supported Question Types and how Answers are read

  • Only short Answer,Linear Scale ,Multi Choice and Checkboxes are supported.
  • Becareful about empty or non answered questions.
  • If you want to use a Question for condition ,it's a good idea to make it mandatory.

Supported Global Functions

The following global functions are currently supported for use in conditions:

  • parseInt(): Parses a string argument and returns a whole number.
  • parseFloat(): Parses a string argument and returns a floating-point number.
  • isNaN(): Determines whether a value is an NaN (Not a Number).

Supported String Functions

The following string functions are currently supported for use in conditions:

  • split(): Splits a string into an array of substrings.
  • repeat(): Returns a new string repeating a specified value a number of times.
  • reverse(): Reverses the order of the characters in a string.
  • trim(): Removes whitespace from the beginning and end of a string.
  • concat(): Joins two or more strings.
  • toLowerCase(): Converts a string to lowercase letters.
  • toUpperCase(): Converts a string to uppercase letters.
  • substr(): Extracts a section of a string.
  • substring(): Extracts a section of a string.
  • indexOf(): Returns the position of the first occurrence of a specified substring in a string.
  • lastIndexOf(): Returns the position of the last occurrence of a specified substring in a string.
  • startsWith(): Checks whether a string starts with a specified substring.
  • endsWith(): Checks whether a string ends with a specified substring.
  • length: Returns the length of a string.
  • includes(): Checks whether a string contains a specified substring.

Supported Array Functions

The following string functions are currently supported for use in conditions:

  • join(): Joins the elements of an array into a string.
  • at(): Returns the character at a specified index in a string.

Important Notes

  • For security reasons, the use of certain Google Apps Script APIs and functions is restricted.
  • There is a maximum length for conditions to prevent complex code execution.

I hope this documentation helps you get started with customizing email content based on logical blocks for Google Forms notifications!