Record Reason for Disqualification

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.

When using disqualification in a survey often there is more than one point at which a response can be disqualified. Unfortunately, there is not a way, within our core application, to easily evaluate how frequently each disqualification point is reached. Fortunately you can accomplish this with some custom scripting!

Above is a report run on a textbox field that we created to store the reason for disqualification that was set with a script. From the results we see that 6 respondents were disqualified for choosing the wrong coffee and another 8 were disqualified for choosing the wrong weapon. Read on to learn how to set this up!

Features used in this example:

  • Page Jump Logic
  • Custom Script Action
  • Our custom scripting function sgapiGetQuestionRuntimeProperty
  • Our custom scripting function sgapiSetValue
  • PHP Foreach Loops

Survey Setup

Start by building all of your survey questions. Once you've have your survey constructed you'll need to set up each of your disqualification points.

To use this script you'll need to set up your disqualification logic using Page Jump Logic to jump to a single disqualify page.

Start by setting up the disqualify page that follows all of your disqualification points. In our example there is simple Text/Instruction element on the page that reads "Disqualified!" Edit the page and on the Logic tab select Yes to flag the page as a Terminal Page. On the page's Page tab select the Response Status Override option to Set response status to "Disqualified."

Your page should look like the following in the survey builder. (We'll come back to this page in a bit to add the script that you see here).

Next, set up the Skip/Disqualify Logic for each of the disqualification points in your survey. To add the logic click Skip/Disqualify Logic. Then, set up your logic conditions and jump the response to your disqualification page.

The disqualification logic in our example looks like so:

We have one disqualification point for the wrong weapon.

And another disqualification point for the wrong coffee.

When you are finished setting up all of your disqualification logic make note of each Exit Logic ID, pictured below. Be sure to write them down in the order that they appear in the survey top to bottom; this is important for the script to work properly. In our example we have 2 disqualify points which have IDs 6 and 7 in that order.

We need just one last element in the survey before we add the script. Add a question to store the disqualify reason that will be set by the script. We used a textbox question which we hid by default on the Logic tab. This can be on any page in your survey except your disqualified page or the thank you page. Make note of this question's ID as well for your script.

The Script

Return to your disqualified page and add a custom script action and paste the below script. You'll want to modify the highlighted portions of your script. If you have more than two disqualification points you can add them, comma separated as "Reason" => Exit Logic ID. As the script comments note, your reason and exit logic array items must be in order as they appear in the survey for the script to work properly!

// Array of Descriptions => IDs for Page Jump Logic Actions.
// These must be **IN ORDER** as they appear in the survey, not ordered by ID!

%%logic = array(
  "Disqualify reason: Wrong weapon!" => 6,
  "Disqualify reason: Wrong coffee!" => 7
);

// Provide the ID of where the message should go on the response

%%reasonID = 5;

//Do not modify below this line
%%reason = "Default value: Check array!"; 

foreach(%%logic as %%key => %%value){
  %%check = sgapiGetQuestionRuntimeProperty(%%value,"Rendered");
  if(%%check == false){
    break;
  }  
  %%reason = %%key;
}

sgapiSetValue(%%reasonID,%%reason);

How does it work?

The script loops through each logic array item and evaulates whether that exit logic ID was rendered using sgapiGetQuestionRuntimeProperty. If it was not rendered then the script does nothing. If the logic was rendered the key value for that array item, which is the reason description, is stored as %%reason. Then in the final step the value of %%reasonID, our textbox question, is set to %%reason!

Test and Run a Report

Record several test responses. You'll want to be sure that you record at least one response per disqualify point. Then review your individual responses and/or run a report to ensure that your disqualify reason feel is populating and reporting like it should.

If you'd like to check it out record a response here:

http://www.surveygizmo.com/s3/1517635/record-dq-reason

Then review the summary report for the statistics on the reason for disqualification:

https://appv3.sgizmo.com/reportsview/?key=160589-2655419-585e8750f38c84cb0f4d0bd9b9e534b1&realtime=true

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!