Piping an alternative text instead of the selected choice text within a loop and merge block | XM Community
Skip to main content

I have a matrix table question like this:
Feature1
.
.
Feature6
and the scale is: A - excellent, B - good, C - satisfactory, D - less than satisfactory, Unfamiliar with this feature

I now have a loop and merge block that asks about the features where C or D was selected.
This is the question:
Why did you rate {FEATURE} as {SCALE SELECTED}?
Ex. Why did you rate Feature1 as satisfactory?

What's the most efficient way to do this?

Look at the piped text for the matrix questions. You're looking for something like this:
Why did you rate ${q://QID126/ChoiceDescription/1} as ${q://QID126/ChoiceGroup/SelectedAnswers/1}


But wouldn't that look like this?
Why did you rate Feature1 as C - satisfactory?
instead of
Why did you rate Feature1 as satisfactory?


Okay. So your problem isn't piping the text, but instead changing text. There are several solutions on the platform, that discuss how to change the question/options text using JS.
Alternatively, you could use display logic. Create four questions for loop and merge. One each for Excellent, Satisfactory etc. In your loop and merge fields use

ChoiceDescription 
and
SelectedAnswers
. Now choose to display the appropriate question without A, B etc. based on the loop and merge field.


I have a matrix table (drop-down) with 6 rows and 5 columns. The columns have recode values from 5 to 1.
I have another matrix table (single select) with the same rows and columns. The columns have the same recode values as the previous matrix table (5 to 1).
I used this JS code to copy the contents of the previous matrix table to the current one:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var r1ar = parseInt("${q://QID25/SelectedAnswerRecode/x2}");
var r2ar = parseInt("${q://QID25/SelectedAnswerRecode/x4}");
var r3ar = parseInt("${q://QID25/SelectedAnswerRecode/x5}");
var r4ar = parseInt("${q://QID25/SelectedAnswerRecode/x6}");
var r5ar = parseInt("${q://QID25/SelectedAnswerRecode/x7}");
var r6ar = parseInt("${q://QID25/SelectedAnswerRecode/x8}");

this.setChoiceValue(1, r1ar, true);
this.setChoiceValue(2, r2ar, true);
this.setChoiceValue(3, r3ar, true);
this.setChoiceValue(4, r4ar, true);
this.setChoiceValue(5, r5ar, true);
this.setChoiceValue(6, r6ar, true);
});

But nothing happens, the current matrix table is empty. None of the selected choices were auto-populated. What do you think is the problem?



Thanks. The requirements changed. They want the questions to display on one page which rules out the loop and merge. There are conditions added to each statement where we only ask the question if they selected 'satisfactory' or 'less than satisfactory'. I think the best solution is to make a hidden duplicate question but using the alternate text for both rows and columns and use that hidden duplicate question to pipe the text I need. I tried it but the code does not seem to work. None of the choices were punched on the hidden question. Here's a snippet of the code that I use:
var r1ar = parseInt("${q://QID25/SelectedAnswerRecode/x2}");
var r2ar = parseInt("${q://QID25/SelectedAnswerRecode/x4}");
var r3ar = parseInt("${q://QID25/SelectedAnswerRecode/x5}");
var r4ar = parseInt("${q://QID25/SelectedAnswerRecode/x6}");
var r5ar = parseInt("${q://QID25/SelectedAnswerRecode/x7}");
var r6ar = parseInt("${q://QID25/SelectedAnswerRecode/x8}");

this.setChoiceValue(1, r1ar, true);
this.setChoiceValue(2, r2ar, true);
this.setChoiceValue(3, r3ar, true);
this.setChoiceValue(4, r4ar, true);
this.setChoiceValue(5, r5ar, true);
this.setChoiceValue(6, r6ar, true);


If your requirement has changed then it would be advisable to ask another question or edit the main question and title before seeking any support from the community as that would help others find the solution in the future.


I did. I posted it here: https://www.qualtrics.com/community/discussion/14255/trying-to-populate-a-matrix-table-with-choices-from-a-previous-matrix-table-question#latest


  1. You could look at using setChoiceValueByRecodeValue  instead, since you are using recode values.

  2. Take a look at
    getChoices 
    and
    getAnswers
    . Sometimes, Qualtrics assigns weird values to these if some changes have been made to the question. So, while you maybe thinking the choices go from 1 to 6...they may actually be going from 13 to 19 internally.

  3. If nothing else works, you can take a look at the following code:

Qualtrics.SurveyEngine.addOnReady(function () {
    // Assuming that the following values were chosen in the previous question
    // You'll get these from the previous answer
    prev_choices = a5, 2, 3, 4, 1, 2];


    // To match the JS indexing scheme (map 1-5 to 0-4 )
    prev_choices = prev_choices.map((item) => (item -= 1));


    // Iterate over each row of the matrix table
    all_rows = this.getQuestionContainer().querySelectorAll("tr");


    // Index starts from 1, as the first row is the header
    for (i = 1; i < all_rows.length; i++) {
        p = prev_choicesti - 1];
        a = all_rowsi].querySelectorAll("        a{p].click();
    }
});



Leave a Reply