Hi All,
I'm completely new to Qualtrics and would like to achieve the following in a survey.
I have a matrix table where 11 statements are rated from 1 to 7. I need to ask a follow up question for the lowest score statement from the matrix table. Like e.g. if statement 3 is rated as the lowest among the 11 statement then I need to ask, why you have given the score (e.g. "Strongly Disagree") for "Statement 3".
If there is a tie, we need to select one statement randomly.
Would this be achieveable with custom scripting?
Thanks
Yes, it is achievable. It is easier if the follow-up question is a on the next page.
https://community.qualtrics.com/XMcommunity/discussion/comment/43849#Comment_43849Hi, thanks. I am looking for the script to achieve this. Can you please help?
Hi there,
the way would be to create two embedded data fields:
lowestScore and selectedItem
then recode the answer choices in the matrix question: 9 not applicable else 1 to 10.
then add the below javaScript onPage Submit in the matrix question;
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
let questionInfo = Qualtrics.SurveyEngine.QuestionInfo
let answerChoices = questionInfo[this.questionId]["Choices"]
let dicAnswers = {};
for(let choiceID in answerChoices){
dicAnswers[answerChoices[choiceID].Text] = Number(this.getChoiceRecodeValue(this.getSelectedAnswerValue(choiceID)))
}
let dicAnswersSorted = Object.entries(dicAnswers).sort(([_a, a], [_b, b]) => a - b)
let lowestValue = dicAnswersSorted[0][1]
let elegibleStatements = new Array;
for(let keys in dicAnswersSorted){
if(dicAnswersSorted[keys][1] == lowestValue){
elegibleStatements.push(dicAnswersSorted[keys][0])
}
}
let randomItem = Math.floor(Math.random() * elegibleStatements.length);
let selectedStatement = elegibleStatements[randomItem]
Qualtrics.SurveyEngine.setEmbeddedData("lowestScore", lowestValue);
Qualtrics.SurveyEngine.setEmbeddedData("selectedStatement", selectedStatement);
});
create the open text question on a new page with page break and insert the lowestScore and selectedStatement as piped text in the question text
Hope this helps
BEst regards
Rudi
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.