Script: workaround for SG problem with optional rows in a grid where the other rows are required.


This isn’t a question – hopefully it will help others who have encountered the same problem.

Sometimes SurveyGizmo is too agile for their own good.  

I wanted to use a radio button grid with several predefined rows (required), and a couple of optional rows.  Making the question required didn’t work because the optional rows were also required.  Eventually I figured out that making the question “not-required” and making all the predefined rows required, while leaving the optional rows “not-required”.  This solution was much cleaner than alternatives such as asking about other attributes after the grid question.  We completed programming, then the client tested and signed off.  Then there was a delay before we received lists for the email campaign, and in the meantime the functionality stopped working.

The alternative suggested by the SG chat agent might have been OK (setting up minimum number of rows answered) but I didn’t want the possibility that someone would fill out an optional row and leave a predefined row empty.  Here’s the script I wrote.  Q10 is the grid question and Q10ErrMsg is the error message just above Q10 which is hidden by default.

I’m sure this could be better, and hopefully SG will fix the issue properly.  But this will allow us to launch.  [The reason it works at all is that the optional rows aren’t really part of the same question.  The script is on an interstitial page right after the page with Q10. The output statements don’t need to be commented out because the script page is not really shown, but you might want to comment out the lines with sgapiJumpToPage for debugging]


/* Script to workaround SG problem with optional rows in a grid */
%%Q10ErrMsgID = 327;
%%Q10_ID = 95; //Table question
%%Q10DefinedRows = 8;
%%Q10AnsweredCount = 0;
%%Q10PageID = 9;
%%NextPageID = 11;

%%Q10array = sgapiGetValue (%%Q10_ID);
%%output .= “Q10 array = ” . sgapiPrint_R (%%Q10array) . “<br/>”;

//The first foreach loop iterates through each row of a grid question
foreach (sgapiGetValue(%%Q10_ID) as %%rowid => %%rowarray){
//The second foreach loop iterates through all of the answers for each row
foreach (%%rowarray as %%optionsku => %%reportingvalue){
%%output .= ‘Question ‘ . sgapiGetTitle(%%Q10_ID);
%%output .= ‘: The answer to row ‘. sgapiGetTitle(%%rowid).’ is ‘. %%reportingvalue;
%%output .= ‘<br>’;
%%Q10AnsweredRows ++;

%%output .= “Q10 rows answered: “. %%Q10AnsweredRows . “<br/>”;

if (%%Q10AnsweredRows < %%Q10DefinedRows) {
else {


Mike Pritchard asked


    Question stats

    • Active
    • Views1531 times
    • Answers0 answers
    • Followers1 follower