Setting Continuous Sum Max Total Value Dynamically

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.

The Continuous Sum question is a very popular question, particularly with our market research users. Often survey designers are looking to make sure that the continuous sum total matches another value that the respondent entered. In this tutorial, we'll cover a script for dynamically defining the maximum total value for a continuous sum question from an answer to a previous question.

Check it out in an example survey!

OR

Download this survey to your account!

Estimated implementation and testing time: 5-10 minutes

We'll be using the following SurveyGizmo features and functions in this workaround:

The Script

This script will set the Max Total property of a continuous sum question to the value entered in a specified textbox list row, textbox, or slider.

You will need to customize highlighted IDs.

If your source is Textbox List Row

The %%source_option_sku variable defines the option SKU of the textbox we are taking the value from in the survey. Not sure how to find your option SKU? Check out our How To Find IDs document!

If your source is a Textbox or Slider

Set %%source_option_sku = 0.

//Setting the max value of a continuous sum question dynamically
%%source_id = 2; // Source Textbox or Textbox list row question ID
%%target_id = 3; //Target Continuous Sum question ID
%%next_pageid = 2; // Page id of the next page to jump to if the respondent has keyed in zero hours
%%source_option_sku = 10002; // Option ID from textbox list. Set value as 0 if %%source_id is a Textbox.

%%source_value = sgapiGetValue(%%source_id); //values of source textbox list q
%%property = 'max_total';

if(sgapiIsArray(%%source_value)){

   sgapiSetQuestionProperty(%%target_id, %%property, %%source_value["%%source_option_sku"]);
   if(!(%%source_value["%%source_option_sku"] > 0)){

      sgapiJumpToPage(%%next_pageid);

   }
}

else {

   sgapiSetQuestionProperty(%%target_id, %%property, %%source_value);  
   if(!(%%source_value > 0)){

      sgapiJumpToPage(%%next_pageid);

   }
}

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!