Randomly show a dynamic number of rows


In my survey respondents indicate how many service lines they are involved in and then are later asked about these. I’m trying to set-up a grid question so that the number of services (rows) shown is based on the answer count to the previous multi-select question and that this number is not greater than 5 (so the question isn’t too long). I have found the custom script for randomly showing a subset of rows but if I set the number at 5 and the respondent is involved in fewer than 5 service lines, irrelevant services/rows are shown. I have found a way of counting the number of services selected at the prior question and can use this in place of the number 5 but I get 2 problems:

  1. If more than 5 services/rows are selected, the question gets too long
  2. Even though the ‘answer count’ function works and displays as many rows as are selected in the prior question, I always get an error message ‘Script Failed: Bad Script’

Here’s my script so far …

//Row IDs to be randomly hidden go here. Make sure they are comma separated, no spaces, and inside quotes.

%%questionsHideRan = “448,449,450,451,452,453,454,455,456,457,458,459,460,461,530” ;


//Number of rows you want shown from the list above. No quotes or commas are needed.

%%shown = [question(“answer count”), id=”142″];


//Do not change after this line.

%%arr = sgapiExplode(‘,’,%%questionsHideRan);


foreach(%%arr as %%question)




for (%%i=0; %%i<%%shown; %%i++)





I have tried a number of ways of stating the ‘answer count’ bit and amazingly these all work in terms of showing the number of rows selected in the prior question but I always get the error message. E.g. answercount(142) OR { [question(“answer count”), id=”142″]}

Anton answered

    This is a bit outside my comfort level in scripting. In case you haven’t made progress on this, one option that you might consider is to consult with SurveyGizmo’s Programming Services Team:


    They can consult and assist with custom solutions like the one that you’re after.


    Dominic Sharpe answered

      Hi Dominic, thank you. Was hoping to script this myself but yes that’s an option

      Anton answered


        Question stats

        • Active
        • Views1137 times
        • Answers2 answers
        • Followers1 follower