Disqualify Based on Previously Collected Data

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

Looking for a way to disqualify a respondent based on an email address or customer ID# that has already been entered in your survey? Not a problem! This script will check your survey's database for a particular question to see if the same data has been entered before.

Check it out in an example survey!

Example Survey

  1. Type in your email address and click Submit (After 10 seconds the survey will redirect and start you at the beginning of the survey again)
  2. Take the survey a second time to see that you're disqualified!

This script uses the following features and custom scripting functions:

  • Textbox or validated Textbox Question
  • Custom Script Action
  • sgapiGetValue
  • sgapiList
  • sgapiDisqualify
  • sgapiJumpToPage

The Script

%%qid = 2;
%%email = sgapiGetValue(%%qid);
%%sid = 1055037;
%%message = "Sorry, you have already registered using this email address.";

%%filter = "&filter[field][0]=[question('.%%qid.')]&filter[operator][0]==&filter[value][0]=".%%email."&filter[field][1]=status&filter[operator][1]==&filter[value][1]=Complete";
%%api = sgapiList(%%sid,1,1,%%filter);

if(%%api['total_count'] > 0)
{
sgapiDisqualify(%%message);
} else {
  sgapiJumpToPage(5);
}

In the script above you will need to customize specific variables. There are three variables that are required to be changed to apply this code to your survey.

Required Customizations

%%qid- This variable will indicate the question ID of the text field you'd like the script to pull data from.  

%%sid - This variable indicates the Survey ID of the survey. You will need to change this survey ID anytime you add it to a new survey. 

%%message - This variable is the disqualify message that is displayed to the disqualified respondent.

Optional Customizations

%%email - This variable does not need to be an email address, you can change this to any question you wish to base your disqualify logic on. So, for example, if you'd like to disqualify based on first or last name you could customize the variable to something like %%fname.

Setup

For the purposes of this example, we're going to be using an email field to disqualify. You can use any textbox field that you'd like as long as you're using a textbox question type or validated textbox.

On a page that follows the email textbox, add a Custom Script action and paste the above script. Modify the script with your question ID, survey ID, and disqualification message.

Reorder the Custom Script action to the top of the page. This action MUST be at the top of the page.  

Preview and test! You should always test your survey prior to distributing it to make sure the custom script is working properly.

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!