Custom Script using JavaScript

Custom Script using JavaScript

JavaScript is a powerful and widely-adopted programming language that excels in client-side scripting within web browsers. It allows developers to create dynamic and interactive web applications. In Zoho Survey, you can leverage JavaScript for implementing conditions and piping within various modules, enhancing the customization and functionality of your surveys. This capability enables you to tailor the user experience based on responses, making your surveys more engaging and effective.

JavaScript for Conditions 

How to add JavaScript for Question Display logic: 

To add a custom script in question:

  1. Go to Builder>Editor and add the question type you'd like to use on the Survey Builder page using drag and drop or clicking on it in the left pane.

  2. Click on the Insert Variable dropdown in the top-right corner and choose JavaScript Snippet.

  1. Enter the code. Click insert variable(inside one) to use built-in functions in your code.

  2. Click Test with sample data.

  3. Click the Run button and check your result.

  4. Click the Save button.

How to add a JavaScript for Answer display logic : 

To add a custom script for answer display logic:

  1. Go to Builder>Editor and add the question type you'd like to use on the Survey Builder page by drag and drop or clicking on it in the left pane.

  2. Navigate to Answer Display Logic and click Add Logic.

  1. Click If and select the JavaScript snippet.

  2. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.

  1. Click UPDATE and SAVE the code.

 How to add a JavaScript for Page Skip logic : 

To add a custom script for Page Skip Logic:

  1. Go to Builder>Editor and click the Logic icon at the top-right corner of the page. Select Page Skip Logic.

  1. In the new window, click Add Condition. Click If and select JavaScript Snippet.

  1. Add the required custom script. You can also test run the code to ensure the logic works.

  2. In the Default Flow, select the page to skip when the custom script logic works.

 How to add a JavaScript for Trigger Email: 

To add a custom script for Trigger Email:

  1. Go to Builder>Hub>Triggers and click the CREATE Trigger Emails.

  1. Click the ADD CONDITON button at the top-right corner.

  1. Click If and select JavaScript Snippet.

  1. Add the required custom script. You can also test run the code to ensure the logic works.

  2. Add your sender email address andany  other necessary fields to the email settings for sending the email when the custom script condition returns True.

 How to add a JavaScript for the Survey End Page logic: 

To add a custom script for Survey End page logic:

  1. Go to Builder>Settings>Survey End page and click Add Logic.

  2. Click If and select Javascript snippet from the dropdown.

  1. Add the required custom script. You can also test run the code to ensure the logic works.

  2. In the Default Flow, select the page to skip when the custom script logic works.

  1. Click SAVE at the bottom of the page to confirm the changes.

 JavaScript for Piping 

 1.  Survey End Page  

JavaScript can be used for piping in 2 places, namely in the Custom message and in Re-direct to a new page when it comes to the Survey End Page customization.

    1. Custom Message

To add a custom script for a custom message in the Survey End page:

  1. Go to Builder>Settings>Survey End Page and click Add Logic.

  1. Click If, scroll down, and select Javascript Snippet.

  1. Add the custom script required for piping and test run the code to ensure it works.

  2. Choose the desired action when the piping works under the then section.

  3. Click SAVE.

    1. Re-direct to a New Page

To add a custom script to redirect to a new page in the Survey End page:

  1. Go to Builder>Settings>Survey End Page and scroll down to the Default end page section. Choose the Redirect to a new page option.

  1. Click the Insert Variable icon, scroll down, and select Javascript Snippet.

  1. Add the custom script required for piping, then test run the code to ensure it works. If it works, click SAVE.  

  2. Add the piping parameter to the URL to which the survey should redirect, then click SAVE.

 2. Survey Disqualification page 

    1. Custom Message

For adding a custom script for a Custom Message in the Survey Disqualification Page, follow the steps below:

  1. Go to Builder>Settings>Survey Disqualification Page and choose the Custom Message option.

  1. Click Insert Variable, scroll down, and choose Javascript Snippet.

  1. Add the custom script required for piping in the window that opens, then test run the code to ensure it works. Then click SAVE.

    1. Re-direct to a New Page

To add a custom script to redirect to a new page in the Survey Disqualification page:

  1. Go to Builder>Settings>Survey Disqualification Page and select the Redirect to a new page option.

  1. Click the Insert Variable icon, scroll down, and select Javascript Snippet.

  1. In the window that opens, add the custom script required for piping and test run the code to ensure it works. If it works, click SAVE.  

  2. Add the piping parameter to the URL to which the survey should redirect, then click SAVE.

 

 Javascript for Integrations

 How to add JavaScript for Webhook: 

Follow the steps below for adding a JavaScript script for Webhook integrations:
  1. Navigate to Builder > Hub > Triggers and click the CREATE button for Webhook.

  2. Provide a name for the Webhook and add the POST URL.

  3. Enter a name in the Request Body for the key.
  4. Add the value subsequently by scrolling down and selecting Javascript from the custom script options

  5. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.
  6. Add the query parameter also using a custom script if required.
  7. Add the Header details and click SAVE.
 

How to add JavaScript for Power BI: 

  1. Follow the steps below for adding a JavaScript for Power BI integrations:

  2. Navigate to Builder > Hub > Integrations and click the CREATE button for Power BI.

  3. Provide a name for the Power BI and add the POST URL.

  4. In the Request Body, enter a name for the key. Subsequently, scroll down and select Javascript from the custom script options.
  5. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.
  6. Click SAVE.
 

 How to add JavaScript for Zoho CRM: 

  1. Navigate to Builder > Hub > Integrations and click the INTEGRATE button in Zoho CRM

  2. Select the environment you wish to pass the responses, then click NEXT.

  3. Select the CRM modules from which values should be passed to Zoho survey using the dropdown button.

  4. Select the type of action that needs to be performed. Under the value to be passed on, scroll down and select Javascript from the custom script options.

  5. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.
  6. Click SAVE.

How to add JavaScript for Zoho Recruit: 

  1. Navigate to Builder > Hub > Integrations and click the INTEGRATE button on Zoho Recruit.

  2.  Select the MODULES you wish to pass the responses, then click NEXT.

  3. Select the type of action that needs to be performed. Under the value to be passed on, scroll down and select Javascript from the custom script options.

  4. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.
  5. Click SAVE.
   

How to add JavaScript for Google Sheets 

  1. Navigate to Builder > Hub > Integrations and click the INTEGRATE button on Google Sheets.

  2. Select the spreadsheet and questions that need to be integrated and click NEXT.

  3. In the Google Sheet integration page, click the + button.

  4. Under select question, scroll down and select Javascript from the custom script options.

  5. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.

  6. Finally, click SAVE.

How to add JavaScript for Zoho Sheets 

  1. Navigate to Builder > Hub > Integrations and click the INTEGRATE button In Zoho Sheets.

  2. Select the spreadsheet and questions that need to be integrated and click NEXT.

  3. In the Zoho Sheet integration page, click the + button. You may need to scroll down, depending on the number of questions.

  4. Under Select question, scroll down and select Javascript from the custom script options.

  5. Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.

  6. Click SAVE.

Points To Note 

The following keywords are restricted to be saved in JavaScript :

 

console

window

alert

this

self

new

class

await

worker

debugger

async

import

export

try

catch

throw

finally

resolve

reject

super

extends

pause

play

then

remove

object

function

promise

globalThis

image

xmlhttprequest

xmldocument

geolocation

formdata

file

event

websocket

urlpattern

formdata

document

sessionstorage

localstorage

cookie

clearinterval

usb

cleartimeout

postmessage

prompt

setintervals

settimeout

cache

bluetooth

payment

otp

database

global_object

eval

arguements

global-fucn

canvas

strict

audio

navigation

navigator

 

  • While using script conditions in URL Parameter, you must enter  the param value inside square brackets []. For example, application. survey.urlparam ["userName"] in JavaScript, because special characters are not allowed in the JSON key in dot notation.

  • To avoid syntax errors, javascript code should contain javascript syntax, and it should always end either with a semicolon or be properly wrapped inside curly braces.

 Sample Reference 

A sample reference Java script snippet code to achieve a simple arithmetic  operation :

The given code combines arithmetic operations and conditional statements to make decisions based on the values of certain variables or expressions.

 

var rating = application.survey.question.C.response +           application.survey.question.D.response;

if (application.survey.question.A.response == "Single"

application.survey.question.B.response == 2)

{

    return true;

}

else if (rating > 10)

{

    return true;



    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION





                          Quick LinksWorkflow AutomationData Collection
                          Web FormsEnterpriseBegin Data Collection
                          Interactive FormsWorkplaceData Collection App
                          CRM FormsCustomer ServiceAccessible Forms
                          Digital FormsMarketingForms for Small Business
                          HTML FormsEducationForms for Enterprise
                          Contact FormsE-commerceForms for any business
                          Lead Generation FormsHealthcareForms for Startups
                          Wordpress FormsCustomer onboardingOrder Forms for Small Business
                          No Code FormsConstructionRSVP tool for holidays
                          Free FormsTravel
                          Prefill FormsNon-Profit

                          Intake FormsLegal
                          Mobile App
                          Form DesignerHR
                          Mobile Forms
                          Card FormsFoodOffline Forms
                          Assign FormsPhotography
                          Mobile Forms Features
                          Translate FormsReal EstateKiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for FormsAlternativesSecurity & Compliance
                          Holiday FormsGoogle Forms alternative GDPR
                          Form to PDFJotform alternativeHIPAA Forms
                          Email Forms
                          Encrypted Forms
                          Embeddable Forms
                          Secure Forms
                          Drag & drop form builder
                          WCAG



                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media


                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Custom Script Overview

                                                                                                                If you want your survey to make decisions based on a complex logic, you can enable this by using Custom Scripts. Simply put, Custom Scripts are short transcripts of code that'll run in the backend of the survey based on the input received from the ...
                                                                                                              • Custom Script using Deluge

                                                                                                                Deluge is a scripting language specifically designed for the Zoho ecosystem. It stands for Data Enriched Language for the Universal Grid Environment and is tailored to help users automate tasks and customize applications across Zoho's suite of ...
                                                                                                              • Custom V​ariables

                                                                                                                Zoho Survey offers the following advanced features that take your surveying experience to a new level. Custom Variables Scoring Invite Reviewer Share Survey Send Copy Transfer Survey Export as PDF Print Survey Using custom variables allows you to ...
                                                                                                              • I want to use the answer of a particular question on page one of the survey as a variable in a question on the subsequent page. Is there a limitation in using custom variables on different pages?

                                                                                                                No, there is no restriction in using variables on different pages. To pipe in the response to the previous question into the following question, click Insert Variable and select the question for which you wish to add a follow-up question. Read ...
                                                                                                              • Custom Report

                                                                                                                You can select questions and create customized reports. These reports can be shared or chosen by filter to show responses for specific questions. To create a custom report: Click Create in the Custom Report section. Enter a name in the Report name ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources