I have a question A of type checkbox list. Respondent can choose any number of options. But in the next question B of the form radiobutton grid I need show in columns only 6 answers N answers given to question A.
This is done not to stretch radiobutton grid.
I found something similar to the code I need, but I do not know how to improve it for my specific needs
Thank you all for helping me in advance
Here a solution which worked for me. Just copy the code below in a custom script and change the question ID’s. What you get as a result from the script: a radio button or checkbox question containing max. 6 randomly chosen options the respondent has given in the source question. Then you can use this resulting question as source for a piping in the columns of your radio grid.
//Source: a multiple choice checkbox question answered by the respondent. In this example with question ID 150
//Target (result): a multiple choice question containing only a given maximum of the options which have been ticked by the respondent in source question. In this example with the question ID 152
%%arr=sgapiGetValue(150);//get the answers of the question as an array
sgapiShuffle(%%arr);//generate a random order of the answers
%%toshow=6;//number of options to show in the subsequent question
%%todelete=sgapiCount(%%arr)-%%toshow;//variable %%todelete=number of answers to delete
for (%%i=0; %%i<%%todelete; %%i++)//loop: removing the last %%todelete answers in the array
%%scratch=sgapiArray_Pop(%%arr);//removes the last element in the array
sgapiSetValue(152,%%arr);//write the remaining answers as answer options in the subsequent questions