Saving matrix responses to embedded data | XM Community
Skip to main content

I have two sets of embedded data in the survey flow…

A1          A1ess

A2          A2ess

A3          A3ess

…            …

A10        A10ess

I wrote some JavaScript that randomizes an array of text elements and stores the individual elements into A1 - A10. The other set of embedded data fields, A1ess - A10ess, are all set equal to zero in the survey flow. That part is working fine.

I then pipe A1-A10 into the statements of a matrix question that asks the user to rate each statement as essential, beneficial, or not necessary …

For all the statements for which the user rates them as essential, I want to change the A#ess data field to 1. A simple boolean flag indicating that this field has been rated as essential.

For example, if the third statement in the matrix question is rated as essential, then A3ess would be set equal to 1.

I’m floundering around trying to write some JavaScript to do this. Nothing is even close to working. Any help would be greatly appreciated.

Thanks

 

@LarryKap Add this JavaScript to your question

Qualtrics.SurveyEngine.addOnReady(function() {
var QID = this.questionId;

jQuery('.c4 inputttype="radio"], .c5 inputttype="radio"], .c6 inputttype="radio"]').on('change', function() {

var radioButtonID = jQuery(this).attr('id');
console.log('Radio Button ID:', radioButtonID);

var matches = radioButtonID.match(/QR~QID\d+~(\d+)~(\d+)/);
if (matches && matches.length === 3) {
var statementNumber = parseInt(matchess1]);
var choiceNumber = parseInt(matchess2]);
console.log('Statement Number:', statementNumber);
console.log('Choice Number:', choiceNumber);

var essField = 'A' + statementNumber + 'ess';

if (choiceNumber === 1) {
Qualtrics.SurveyEngine.setEmbeddedData(essField, 1);
console.log(essField + ' = 1');
} else {

Qualtrics.SurveyEngine.setEmbeddedData(essField, 0);
console.log(essField + ' = 0');
}
}
});
});

Hope it works


@LarryKap,

I may be missing something, but it seems you made the whole process more complicated than necessary.  Instead of randomly populating embedded data fields A1 through A10, you could put all your text statements in the matrix and use advanced randomization to evenly display 10 of them.  It would make your data much cleaner and A#ess variables unnecessary.


Hey Tom,

That’s a good point, however, I didn’t go into all the details earlier. It isn’t quite totally random. I need 4 of the 10 to always appear together. All the others should be random and the placement of the 4 should be random, but those 4 need to always be together. It didn’t seem that the builtin randomizer could do that. Let me know if it can because that would be easier. Thanks.


Nam, it works like a charm. Thanks so much.

- Larry


Nam, it works like a charm. Thanks so much.

- Larry

Glad it worked 😁


Hey Tom,

That’s a good point, however, I didn’t go into all the details earlier. It isn’t quite totally random. I need 4 of the 10 to always appear together. All the others should be random and the placement of the 4 should be random, but those 4 need to always be together. It didn’t seem that the builtin randomizer could do that. Let me know if it can because that would be easier. Thanks.

@LarryKap  - You can do that with a combination of advanced randomization and choice groups.


Leave a Reply