Custom code for picking the lowest-rated matrix statement | XM Community
Skip to main content

Hi everyone, 

 

I’m trying to get my code to work but I can’t seem to get it going. Does anyone have any thoughts on it?

I want to select the lowest rated statement and put it into the embedded data that is named as such, my code is below:

 

Qualtrics.SurveyEngine.addOnUnload(function()
{
    var matrixQuestion = 'QID38';
    var numRows = 14;

    var lowestRating = Number.POSITIVE_INFINITY;
    var lowestStatement = '';

    var responseLabels = r
       "${e://Field/QID35_R1}",
        "${e://Field/QID35_R2}",
        "${e://Field/QID35_R3}",
        "${e://Field/QID35_R4}",
        "${e://Field/QID35_R5}",
        "${e://Field/QID35_R6}",
        "${e://Field/QID35_R7}",
        "${e://Field/QID35_R8}",
        "${e://Field/QID35_R9}",
        "${e://Field/QID35_R10}",
        "${e://Field/QID35_R11}",
        "${e://Field/QID35_R12}",
        "${e://Field/QID35_R13}",
        "${e://Field/QID35_R14}"
    ];

    for (var i = 1; i <= numRows; i++) {
        var rating = parseInt(Qualtrics.SurveyEngine.getEmbeddedData(matrixQuestion + '_R' + i));
        if (!isNaN(rating) && rating < lowestRating) {
            lowestRating = rating;
            lowestStatement = responseLabels i - 1];
        }
    }


    Qualtrics.SurveyEngine.setEmbeddedData('lowestRatedStatement', lowestStatement);
});

Hi @JesseN , please have a look at this thread.


Leave a Reply